3 回答
TA贡献1828条经验 获得超3个赞
Class.forName()
TA贡献1808条经验 获得超4个赞
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://<Path to your database i.e. MS Access DB>");Statement s = conn.createStatement();
路径可以类似于E:/Project/Java/DBApp
ResultSet rs = s.executeQuery("SELECT * FROM Course");while(rs.next()) System.out.println(rs.getString("Title") + " " + rs.getString("Code") + " " + rs.getString("Credits"));
TA贡献1936条经验 获得超6个赞
My OS windows 8 64bitEclipse version Standard/SDK Kepler Service Release 2My JDK is jdk-8u5-windows-i586My JRE is jre-8u5-windows-i586
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
ucanaccess-2.0.8.jarcommons-lang-2.6.jar commons-logging-1.1.1.jarhsqldb.jar jackcess-2.0.4.jar
C:\Program Files (x86)\eclipse\lib C:\Program Files (x86)\eclipse\lib\ext
public static void main(String[] args) { try { Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\Hasith\\Documents\\JavaDatabase1.mdb"); Statement stment = conn.createStatement(); String qry = "SELECT * FROM Table1"; ResultSet rs = stment.executeQuery(qry); while(rs.next()) { String id = rs.getString("ID") ; String fname = rs.getString("Nama"); System.out.println(id + fname); } } catch(Exception err) { System.out.println(err); } //System.out.println("Hasith Sithila");}
添加回答
举报