/**
* constructor
* @param strUser database user
* @param strPassword user password
*/
public DBOperation(String strUser, String strPassword) {
this();
this.strUser = strUser;
this.strPassword = strPassword;
}
/**
* execute query and retrive the data
* @param strSql SQL string( select )
* @return result data
*
* @throws SQLException
*/
public ResultSet executeQuery( String strSql ) throws SQLException {
// clear result set
result = null;
// get Connection
conn = DriverManager.getConnection( strConn, strUser, strPassword );
Statement st = conn.createStatement();
// query
return st.executeQuery( strSql );
}
/**
* modify the data in database
* @param strSql SQL string ( delete, insert and update )
* @return execute result
* -1: error
* other: normal(the count of the data rows modified )
*
* @throws SQLException
*/
public int executeUpdate( String strSql ) throws SQLException {
// return value
int nRetValue = -1;
// get connection
conn = DriverManager.getConnection( strConn, strUser, strPassword );
Statement st = conn.createStatement();
// update
nRetValue = st.executeUpdate( strSql );
// close Statement and Connection
st.close();
conn.close();