jsp sql执行代码
package com.db;
import java.sql.*;
public class ExecuteDB extends Connect{
private Connection conn;
private Statement stmt;
private ResultSet rs;
private String errorMessage;
public ExecuteDB()
{
conn=super.getConn();
stmt=null;
rs=null;
this.errorMessage=super.getErrorMessage();
}
public boolean exeSql(String strSql)
{
boolean isSuc=false;
try{
stmt=conn.createStatement();
stmt.executeUpdate(strSql);
stmt.close();
isSuc=true;
}
catch(Exception e)
{
this.errorMessage=this.errorMessage+"<br>"+e.toString();
}
return isSuc;
}
public ResultSet exeQuery(String strSql)
{
try{
stmt=conn.createStatement();
rs=stmt.executeQuery(strSql);
}
catch(Exception e)
{
this.errorMessage=this.errorMessage+"<br>"+e.toString();
rs=null;
}
return rs;
}
public String getErrorMessage()
{
return errorMessage;
}
}