jdbc Statement 和CallableStatement 和 PreparedStatement

Statement用法:

String sql = "select seq_orderdetailid.nextval as test dual";
Statement stat1=conn.createStatement();
ResultSet rs1 = stat1.executeQuery(sql);
if ( rs1.next() ) {
	id = rs1.getLong(1);
}


INOUT参数使用:

CallableStatement cstmt = conn.prepareCall("{call revise_total(?)}");
cstmt.setByte(1, 25);
cstmt.registerOutParameter(1, java.sql.Types.TINYINT);
cstmt.executeUpdate();
byte x = cstmt.getByte(1);


Statement的Batch使用:

Statement stmt  = conn.createStatement();
String sql = null;
for(int i =0;i<20;i++){
	sql = "insert into test(id,name)values("+i+","+i+"_name)";
	stmt.addBatch(sql);
}
stmt.executeBatch();


PreparedStatement的Batch使用:

PreparedStatement pstmt  = con.prepareStatement("UPDATE EMPLOYEES  SET SALARY = ? WHERE ID =?");
for(int i =0;i<length;i++){
	pstmt.setBigDecimal(1, param1[i]);
	pstmt.setInt(2, param2[i]);
	pstmt.addBatch();
}
pstmt.executeBatch();


PreparedStatement用法:

PreparedStatement pstmt  = con.prepareStatement("UPDATE EMPLOYEES  SET SALARY = ? WHERE ID =?");
pstmt.setBigDecimal(1, 153.00);
pstmt.setInt(2, 1102);
pstmt. executeUpdate()
;

你可能感兴趣的:(statement)