我以前是做.net 的,数据库操作从来没有像java这么复杂的,现在我一直不明白Statement是用来干什么的, 还有建立了Connection ,不用打开就可以操作吗?怎么没有open方法呀
还有以下这两打语句对吗?(t是返回一个Statement)
ResultSet rs=t.getStatement().executeQuery("select count(*) from biao");
int c=t.getStatement().executeUpdate("delete from biao where id=2");System.out.println(rs.getInt(1));
可以一起这么写吗??
谢谢前辈们指点!
还有以下这两打语句对吗?(t是返回一个Statement)
ResultSet rs=t.getStatement().executeQuery("select count(*) from biao");
int c=t.getStatement().executeUpdate("delete from biao where id=2");System.out.println(rs.getInt(1));
可以一起这么写吗??
谢谢前辈们指点!
看下这个,呵呵。
try{
PreparedStatement stmt = t.t.getStatement();
ResultSet rs=stmt.executeQuery("select count(*) from biao");
rs.close();
stmt.close();
stmt = t.t.getStatement();
int c=t.getStatement().executeUpdate("delete from biao where id=2");
catch(Exception e){}
finally{
stmt.close();
}