Java操作数据库问题 res = sql.executeQuery();// 所以接连都成功,但这行报错是怎么回事
publicstaticvoidmain(String[]args){TestSql_3TS=newTestSql_3();conn=TS.getConnection()...
public static void main(String[] args) {
TestSql_3 TS = new TestSql_3();
conn = TS.getConnection();
try{
sql = conn.prepareStatement("select * from 课程表");
res = sql.executeQuery();// 所以接连都成功,但这行报错是怎么回事
System.out.println("执行增加,修改,删除前数据");
while(res.next()){
String Kid = res.getString("课程号");
String Kna = res.getString("课程名");
System.out.print(" 课程号:"+Kid);
System.out.println(" 课程名:"+Kna);
}
sql = conn.prepareStatement( "insert into 课程表 values(?,?)" );
sql.setInt(1,11);
sql.setString(2,"29lu");
sql.executeUpdate();
}
catch(Exception e){
e.printStackTrace();
}
} 展开
TestSql_3 TS = new TestSql_3();
conn = TS.getConnection();
try{
sql = conn.prepareStatement("select * from 课程表");
res = sql.executeQuery();// 所以接连都成功,但这行报错是怎么回事
System.out.println("执行增加,修改,删除前数据");
while(res.next()){
String Kid = res.getString("课程号");
String Kna = res.getString("课程名");
System.out.print(" 课程号:"+Kid);
System.out.println(" 课程名:"+Kna);
}
sql = conn.prepareStatement( "insert into 课程表 values(?,?)" );
sql.setInt(1,11);
sql.setString(2,"29lu");
sql.executeUpdate();
}
catch(Exception e){
e.printStackTrace();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询