我输入了这段代码,但没有记录来自数据库...我已经附加了Ms Access数据库 需要帮助... 输出只表示"建立成功"。
import java.sql.*;
public class Db {
Connection con;
Statement st;
ResultSet rs;
//constructor
public Db(){
connect();
}
//connect funtion
public void connect(){
try {
String driver;
driver = "sun.jdbc.odbc.JbdcObdcDriver";
Class.forName(driver);
String db;
db="jbdc:obdc:db2";
//connectin to db
con=DriverManager.getConnection(db);
String sql;
sql="Select * from Table1";
rs=st.executeQuery(sql);
while (rs.next()){
String fname=rs.getString("FirstName");
String lname=rs.getString("LastName");
String age=rs.getString("age");
System.out.println(fname+" "+lname+" "+age);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void main(String[] args) {
// TODO code application logic here
}
Db d=new Db();