jdbc从mysql数据库中查出数据的id为0
Listlist=newArrayList();Connectioncon=super.getconn();PreparedStatementpst=null;Resul...
List list=new ArrayList();
Connection con=super.getconn();
PreparedStatement pst=null;
ResultSet rs=null;
try {
pst=con.prepareStatement("select * from Type");
rs= pst.executeQuery();
while(rs.next())
{
Type type=new Type();
type.setTNum(rs.getString("tNum"));
type.setTypeName(rs.getString("typeName"));
list.add(type);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
super.closeall(rs, pst, con);
}
return list;
这是我写的代码,查出来的数据的id为0,请大家帮忙看一下吧,谢谢 展开
Connection con=super.getconn();
PreparedStatement pst=null;
ResultSet rs=null;
try {
pst=con.prepareStatement("select * from Type");
rs= pst.executeQuery();
while(rs.next())
{
Type type=new Type();
type.setTNum(rs.getString("tNum"));
type.setTypeName(rs.getString("typeName"));
list.add(type);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
super.closeall(rs, pst, con);
}
return list;
这是我写的代码,查出来的数据的id为0,请大家帮忙看一下吧,谢谢 展开
2个回答
展开全部
....晕
Class.forName("com.mysql.jdbc.Driver ");//注册mysql驱动
System.out.println("加载Driver类成功");
//建立数据库连接
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ pubs ", "pubs","pubs");//得到数据库连接,设定数据库
System.out.println("建立连接成功");
stmt = conn.createStatement();
String sql = "select * from customers";
//执行SQL语句,返回结果集
rs = stmt.executeQuery(sql);//执行查询方法
System.out.println("SQL语句执行成功");
//遍历结果集内容
while (rs.next ()) {//遍历结果集
int job_id = rs.getInt(1);
String job_desc = rs.getString(2);//string类型
int min_lvl = rs.getInt(3);//int
int max_lvl = rs.getInt(4);//int
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
Class.forName("com.mysql.jdbc.Driver ");//注册mysql驱动
System.out.println("加载Driver类成功");
//建立数据库连接
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ pubs ", "pubs","pubs");//得到数据库连接,设定数据库
System.out.println("建立连接成功");
stmt = conn.createStatement();
String sql = "select * from customers";
//执行SQL语句,返回结果集
rs = stmt.executeQuery(sql);//执行查询方法
System.out.println("SQL语句执行成功");
//遍历结果集内容
while (rs.next ()) {//遍历结果集
int job_id = rs.getInt(1);
String job_desc = rs.getString(2);//string类型
int min_lvl = rs.getInt(3);//int
int max_lvl = rs.getInt(4);//int
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |