a.Statement对象
1)Statement;(简单语句) addBatch() and executeBatch()方法
Statement stmt=conn.createStatement();
stmt.addBatch(“”);
stmt.addBatch(“”);
int []results=stmt.executeBatch();
2) 使用方法Connection.createStatement()得到一个Statement对象
b. PreparedStatement(继承自Statement); (预编译语句)
1) 调用ProparedStatement比statement更为高效;
2) 继承自StatredStatement
3)PreparedStatement pstm =connection.prepareStatement(“update mytable set name=?”+”where acctnum=123”);
pstm.setDate(1,sqlDate);
c.CallableStatement对象 (可调用语句)
1) 通过CallableStatement调用数据库中的存储过程;
2) 继承自PreparedStatement;
3) CallableStatement cstm = connection.prepareCall("{callreturn_student[?,?]}");
cstm.setString(1,"8623034");
cstm.registerOutparameter(2, Types.REAL);
cstm.execute();
float gpa = cstm.getFloat(2);
本文详细介绍了在Java中使用三种不同类型的SQL语句对象:Statement、PreparedStatement和CallableStatement进行数据库操作的方法。包括如何创建这些对象,执行简单的SQL语句,预编译SQL语句,以及调用数据库中的存储过程。
1256

被折叠的 条评论
为什么被折叠?



