例12-5.txt
来自「这是一本java基础教程 对新手上路有很大帮助」· 文本 代码 · 共 35 行
TXT
35 行
import java.net.*;
import java.sql.*;
import com.sun.rowset.*;
public class Example12_5{
public static void main(String args[]){
Connection con;
Statement sql;
ResultSet rs;
CachedRowSetImpl rowSet;
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println(""+e);
}
try{ con=DriverManager.getConnection("jdbc:odbc:hello","","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM message");
rowSet=new CachedRowSetImpl();
rowSet.populate(rs);
con.close(); //现在就可以关闭连接了
while(rowSet.next()){
String number=rowSet.getString(1);
String name=rowSet.getString(2);
Date birth=rowSet.getDate(3);
double height=rowSet.getDouble(4);
System.out.println(number+","+name+","+birth+","+height);
}
con.close();
}
catch(SQLException e){
System.out.println(e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?