改后``出现 org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 5 in the jsp file: /login.jsp Generated servlet error: The method getConnection(String, Properties) in the type DriverManager is not applicable for the arguments (Connection, String)An error occurred at line: 5 in the jsp file: /login.jsp Generated servlet error: con cannot be resolvedAn error occurred at line: 5 in the jsp file: /login.jsp Generated servlet error: con cannot be resolved
把你改后的代码粘上来,给我look!
The method getConnection(String, Properties) in the type DriverManager is not applicable for the arguments (Connection, String) 不是提示这句错了嘛?
org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 5 in the jsp file: /login.jsp
Generated servlet error:
The method getConnection(String, Properties) in the type DriverManager is not applicable for the arguments (Connection, String)An error occurred at line: 5 in the jsp file: /login.jsp
Generated servlet error:
con cannot be resolvedAn error occurred at line: 5 in the jsp file: /login.jsp
Generated servlet error:
con cannot be resolved
不是提示这句错了嘛?
我现在用的数据库连接池文件原码如下:
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.*;
import java.io.*;/**
* Description:数据库的封装操作
* @author:shiyq
* @version 1.0
*/public class connpool{
private Context ctx=null;
private Connection conn = null;
private Statement stmt = null; //有回滚的
private PreparedStatement pstmt = null; //@param查询
// Utility ut=new Utility(); //声明一个汉字内码转换的类 public void init() {
try{
ctx=new InitialContext();
// if(ctx==null)
// throw new Exception("没有匹配的环境");
DataSource ds=(DataSource)ctx.lookup("connectDB");
// if(ds==null)
// throw new Exception("没有匹配数据库");
conn=ds.getConnection();//取得连接池
}catch(Exception e){System.out.println("找不到数据源");}
} /*** 构造数据库的连接和访问类*/
public connpool() throws Exception {
init();
} //有回滚功能的生成器
public void setStmt() throws Exception {
this.stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
//可更新结果集的生成器
public void setDStmt() throws Exception {
this.stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
/***返回状态* @return Statement 状态 */
public Statement getStmt() throws Exception {
return stmt;
}/** * 可回滚的预编译SQL语句 * @param sql SQL语句 */
public void setPstmt(String sql) throws Exception {
this.pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}/** * 返回预设状态 */
public PreparedStatement getPstmt() throws Exception{
return pstmt;
}public void clearParameters() throws SQLException {
pstmt.clearParameters();
pstmt=null;
}/** * 返回连接 * @return Connection 连接 */
public Connection getConnection() {
return conn;
}
/*** 设置对应值 *
* @param index 参数索引
* @param value 对应值
*/
public void setString(int index,String value) throws SQLException {
pstmt.setString(index, value);
}
public void setInt(int index,int value) throws SQLException {
pstmt.setInt(index,value);
}
public void setBoolean(int index,boolean value) throws SQLException {
pstmt.setBoolean(index,value);
}
public void setDate(int index,java.sql.Date value) throws SQLException {
pstmt.setDate(index,value);
}
public void setLong(int index,long value) throws SQLException {
pstmt.setLong(index,value);
}
public void setFloat(int index,float value) throws SQLException {
pstmt.setFloat(index,value);
}
public void setBytes(int index,byte[] value) throws SQLException{
pstmt.setBytes(index,value);
}
public void setTime(int index, java.sql.Time x) throws SQLException{
pstmt.setTime(index,x);
}
public void setTimestamp(int index, java.sql.Timestamp x) throws SQLException{
pstmt.setTimestamp(index,x);
}
public void setAsciiStream(int index,java.io.InputStream x,int length) throws SQLException{
pstmt.setAsciiStream(index,x,length);
}
/*public void setUnicodeStream(int parameterIndex,java.io.InputStream x,int length) throws SQLException{
@Deprecated
pstmt.setUnicodeStream(parameterIndex,x,length);
}*/
public void setBinaryStream(int index,java.io.InputStream x,int length) throws SQLException{
pstmt.setBinaryStream(index,x,length);
}
public void setCharacterStream(int index,java.io.Reader reader,int length) throws SQLException{
pstmt.setCharacterStream(index,reader,length);
}
public void setBlob(int index,Blob x) throws SQLException{
pstmt.setBlob(index,x);
}
public void setClob(int index,Clob x) throws SQLException{
pstmt.setClob(index,x);
}
public void setObject(int index,Object x,int targetSqlType,int scale)throws SQLException{
pstmt.setObject(index,x,targetSqlType,scale);
}
public void setObject(int index,Object x,int targetSqlType)throws SQLException{
pstmt.setObject(index,x,targetSqlType);
}
public void setObject(int index,Object x)throws SQLException{
pstmt.setObject(index,x);
}
/** * 执行一般的SQL语句返回字段集 */
public ResultSet ExeQuery(String sql) throws SQLException {
if (stmt != null) {
return stmt.executeQuery(sql);
}
else return null;
} //执行有预处理功能的查询
public ResultSet ExeQuery() throws SQLException {
if (pstmt != null) {
return pstmt.executeQuery();
}
else return null;
} /*
//** * 执行一般的更新SQL语句 *
public void ExeUpdate(String sql) throws SQLException {
if (stmt != null)
stmt.executeUpdate(sql);
}//执行有预处理功能的更新操作
public void ExeUpdate() throws SQLException {
if (pstmt != null)
pstmt.executeUpdate();
}
*/ public boolean ExeUpdate(String sql) throws SQLException {
boolean flat=false;
if (stmt != null)
if (stmt.executeUpdate(sql)>0) {
flat=true; }
return flat;
}public boolean ExeUpdate() throws SQLException {
boolean flat=false;
if (pstmt != null)
if (pstmt.executeUpdate()>0){
flat=true; }
return flat;
}
/** * 关闭连接 */
public void close() throws Exception {
if (stmt != null) {
stmt.close();
stmt = null;
}
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
if (conn!=null)
{
try{
conn.close();
conn = null;
}finally
{
if(conn!=null)
conn.close();
}
}
if(ctx!=null)
{
try{
ctx.close();
ctx = null;
}finally
{
if(ctx!=null)
ctx.close();
}
}
}
}你拷过去,放到记事本里,后缀名改成java就行了