我正在学习Java在JDBC连接方面遇到麻烦。
以下是我的代码:
公共类DemoPro {
public void test() {
Connection con;
Statement stmt;
ResultSet rs;
System.out.println("Looking for connection");
try{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String dburl="jdbc:ucanaccess://E://WEB Project//SCMPayBoard//Database/SCMEmpPayment.accdb";
con=DriverManager.getConnection(dburl,"","");
System.out.println("Connection successfully");
stmt=con.createStatement();
String verify = "Select * from TestTable";
stmt.executeQuery(verify);
rs = stmt.getResultSet();
System.out.println("Executing Query");
while(rs.next())
{
System.out.println("Result/n/n/n");
System.out.println(rs.getString(2) + " : " + rs.getString(3));
}
System.out.println("Closing Connection");
con.close();
}catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(DemoPro.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
DemoPro dp=new DemoPro();
dp.test();
}
}
输出:寻找联系连接成功执行查询关闭连接建立成功(总时间:1秒)
所有sysout正在执行,但未获取表数据我怎么知道表正在访问我应该怎么做却没有得到预期的结果