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));
}
}
问问题
161 次
1 回答
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();
}
}
祝你好运!
于 2013-02-12T13:42:16.517 回答