Package com.it.util;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet; /** * Database Operations Tool class * 7 Properties 4 Methods (Connection method Close resource method General Query method universal deletion and modification method)/public class Basedao {private static final String DRIVER =
"Oracle.jdbc.driver.OracleDriver";
private static final String URL = "Jdbc:oracle:thin: @localhost: 1521:ORCL";
private static final String USERNAME = "System";
private static final String PASSWORD = "OK";
Con public Connection con = null;
pstmt public PreparedStatement pstmt = null;
RST public ResultSet rst = null;
* * Get connection method/public void Getcon () {try {class.forname (DRIVER);
con = drivermanager.getconnection (URL, USERNAME, PASSWORD);
catch (Exception e) {e.printstacktrace ();
}/* * Shut down resource from inside to outside/public void CloseAll () {try {if (rst!= null) {rst.close ();
} catch (Exception e) {e.printstacktrace ();
try {if (pstmt!= null) {pstmt.close (); } catch (Exception e) {e.printstacktrace ();
try {if (con!= null) {con.close ();
} catch (Exception e) {e.printstacktrace (); }/* * sql:sql statement * Params: parameter (in populate SQL.)
Parameter array) */public void Commonquery (String sql,object[]params) {try {//Get connection This.getcon ();
Gets the Execute SQL object pstmt = con.preparestatement (sql); Right.
Processing, subscript starting from 1 for (int i = 0; i < params.length i++) {pstmt.setobject (i+1, params[i]);
//Get result set rst = Pstmt.executequery ();
catch (Exception e) {e.printstacktrace ();
} public int commonupdate (String sql,object[]params) {int r =-1;
try {//Get connection This.getcon ();
Gets the Execute SQL object pstmt = con.preparestatement (sql); Right.
Process for (int i = 0; i < params.length i++) {pstmt.setobject (i+1, params[i]);
//Get the affected row number R = Pstmt.executeupdate ();
catch (Exception e) {e.printstacktrace ();
} return R;
}
}