public class Txt {
public static void main(String[] args) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:txt");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select eno,ename from emp");
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
}
答案 0 :(得分:1)
您应该关闭代码末尾的连接;
con.close();
使用此示例:
public static void main(String[] args) throws Exception {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:txt");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select eno,ename from emp");
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
catch (SQLException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
// Close the connection
con.close();
}
}
祝你好运!