package numberguess;
import java.sql.*;
public class DataBase {
private Connection conn;
private Statement smt;
ResultSet rs;
private String MQ_USER_INFO;
public String getMQ_USER_INFO() {
return MQ_USER_INFO;
}
public void setMQ_USER_INFO(String mQUSERINFO) {
MQ_USER_INFO = mQUSERINFO;
}
public DataBase(){
String classform = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@192.168.1.3:1521:unionuat";
String userName = "sales_jacdcs";
String userPsd = "sales_jacdcs";
try{
Class.forName(classform).newInstance();
conn = DriverManager.getConnection(url,userName, userPsd);
}catch(Exception e){
System.out.println("连接出错");
e.printStackTrace();
}
}
/* public ResultSet getCount(String tableName){
String sql = "select * from " + tableName;
try{
smt = conn.createStatement();
rs = smt.executeQuery(sql);//MQ_USER_INFO
}catch(Exception e){
System.out.println("查询错误");
e.printStackTrace();
return null;
}
return rs;
}*/
public ResultSet getCount(){
String sql = "select * from " + MQ_USER_INFO;
try{
smt = conn.createStatement();
rs = smt.executeQuery(sql);//MQ_USER_INFO
}catch(Exception e){
System.out.println("查询错误==" + MQ_USER_INFO);
e.printStackTrace();
return null;
}
return rs;
}
}
while(rs.next()){
UserBean ub = new UserBean();
ub.setUserId(rs.getInt(2));
ub.setUsername(rs.getString(3));
ub.setPasswd(rs.getString(4));
ub.setEmail(rs.getString(5));
ub.setGrade(rs.getInt(6));//这个也是可以的。但是在数据库中。他是第二个整数。所以取2
//ub.setGrade(rs.getInt("grade"));
al.add(ub);
}
有异常,要捕获