51,407
社区成员
发帖
与我相关
我的任务
分享package section11_1;
import java.sql.*;
public class Example11_1 {
public static void main(String []args){
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//建立jdbc:odbc桥接器
}catch(ClassNotFoundException e){
System.out.println(e);
}
try{
con=DriverManager.getConnection("jdbc:odbc:myData","","");//建立链接
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM goods WHERE price>3000000");
while(rs.next()){
String name=rs.getString(1);
String number=rs.getString(2);
Date date=rs.getDate("madeTime");
double price=rs.getDouble("price");
System.out.printf("%-6s",name);
System.out.printf("%-4s",number);
System.out.printf("%-15s",date.toString());
System.out.printf("%6s\n",price);
}
con.close();
}catch(SQLException e){
System.out.println(e);
}
}
}
