package firm;
import java.sql.*;
public class firm{
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sConnStr = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=firm";
Connection conn = null;
Statement stmt=null;
ResultSet rs = null;
private String user="sa";
private String pass="qwe";
public firm() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn=DriverManager.getConnection(sConnStr,user,pass);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
try
{
conn= DriverManager.getConnection(sConnStr,user,pass);
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch (SQLException ex) {
System.err.println("aq.executeUpdate: " + ex.getMessage());
}
}
public void closeStmt(){
try
{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try
{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}
那在jsp中具体是怎样调用的,
firm f = new firm();
f.executeUpdate("SQL语句自己写");//更新方法
ResultSet rs = f.executeQuery(("SQL语句自己写"); //查询方法
%>