24,918
社区成员
发帖
与我相关
我的任务
分享<jsp:useBean id="conn" class="dbBean.DBBean" scope="session"/>
这句话 应该没错吧。package dbBean;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBBean
{
private String driverStr = "sun.jdbc.odbc.JdbcOdbcDriver";
private String connStr = "jdbc:odbc:mydbsource";
private Connection conn = null;
private Statement stmt = null;
public DBBean()
{
try
{
Class.forName(this.driverStr);
}
catch (ClassNotFoundException localClassNotFoundException) {
System.out.println(localClassNotFoundException.getMessage());
}
}
public void setDriverStr(String paramString) {
this.driverStr = paramString;
}
public void setConnStr(String paramString) {
this.connStr = paramString;
}
public ResultSet executeQuery(String paramString) {
ResultSet localResultSet = null;
try {
this.conn = DriverManager.getConnection(this.connStr);
this.stmt = this.conn.createStatement();
localResultSet = this.stmt.executeQuery(paramString);
}
catch (SQLException localSQLException) {
System.out.println(localSQLException.getMessage());
}
return localResultSet;
}
public int executeUpdate(String paramString) {
int i = 0;
try {
this.conn = DriverManager.getConnection(this.connStr);
this.stmt = this.conn.createStatement();
i = this.stmt.executeUpdate(paramString);
}
catch (SQLException localSQLException) {
System.out.println(localSQLException.getMessage());
}
return i;
}
public void close() {
try {
this.stmt.close();
this.conn.close();
}
catch (SQLException localSQLException) {
System.out.println(localSQLException.getMessage());
}
}
}