package book.database;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class UsingPreparedStatement {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String dbName="SGCC";
String userName="sgccadmin";
String password="sgccadmin";
String sql="insert into student_basic(id,name,age,score,description) values(?,?,?,?,?)";
Connection con = null;
PreparedStatement psm=null;
try{
con=DBConnector.getOracleConnection(null,null, null, dbName, userName, password);
psm=con.prepareStatement(sql);
psm.setInt(1,5);
psm.setString(2,"wangwu");
psm.setInt(3,20);
psm.setDouble(4,99.3);
psm.setString(5,"This is a girl");
psm.executeUpdate();
}catch(ClassNotFoundException e1){
throw e1;
}catch(SQLException e2){
throw e2;
}finally{
OperateDB.closeStatement(psm);
OperateDB.closeConnection(con);
}
}
}