高分求一个关于Bean的简单问题 你用的什么编辑工具?用Jbuilder等工程管理工具,讲它们作为一个工程就可以实现。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是同在一个工程下,不过我编译是在Dos里编译的,在JBuilder里编译不成功 在mySqlConn.java里面要引用connPoolimport common.*; import common.*;你必须要在mySqlConn.java中引用它需要的类 connPool的大小写写错了private ConnPool connPool; 改成private connPoolconnPool; 就可以了 就算都在一个包里也 需要这样 楼上这种说法根本不对哦同一个包中不用import的类文件最好大写开头 package common;import java.lang.*;import java.sql.*;import java.util.*;import javax.servlet.*;public class ConnPool{ private static final int defaultMaxConnections = 3; private Vector freeConnections; private Hashtable boundConnections; private static final String driverName = "org.gjt.mm.mysql.Driver"; private static final String jdbcURL = "jdbc:mysql://localhost/univessence"; private static final String username = "root"; private static final String password = ""; private int maxConnections; public ConnPool(int numConnections){ maxConnections = numConnections; boundConnections = null; freeConnections = null; } public ConnPool(){ this(defaultMaxConnections); } public void closeDB() throws SQLException{ if (boundConnections != null){ for(Enumeration e = boundConnections.elements(); e.hasMoreElements();){ Connection conn = (Connection)e.nextElement(); conn.close(); } boundConnections.clear(); boundConnections = null; } if (freeConnections != null){ for (Enumeration e = freeConnections.elements(); e.hasMoreElements();){ Connection conn = (Connection)e.nextElement(); conn.close(); } freeConnections.removeAllElements(); freeConnections = null; } } public synchronized Connection getConnection() throws SQLException{ if (freeConnections == null) throw new SQLException( "The connection pool has not been established yet."); if (boundConnections.get(Thread.currentThread()) != null) throw new SQLException( "Cannot get connections over once for this current running thread."); try{ if (freeConnections.size() == 0) wait(); } catch(InterruptedException ex){ throw new SQLException(ex.toString()); } Connection conn = (Connection)freeConnections.firstElement(); freeConnections.removeElement(conn); boundConnections.put(Thread.currentThread(),conn); return conn; } public void openDB(String drvName,String url, String uname,String passwd) throws SQLException{ try{ boundConnections = new Hashtable(maxConnections); freeConnections = new Vector(maxConnections); Class.forName(drvName); for (int i=0;i<maxConnections;i++) freeConnections.addElement( DriverManager.getConnection(url,uname,passwd)); } catch(Exception ex){ boundConnections = null; freeConnections = null; throw new SQLException(ex.toString()); } } public synchronized void returnConnection() throws SQLException{ Connection conn = (Connection)boundConnections.remove( Thread.currentThread()); if (conn == null) throw new SQLException( "The connection which this current running thread got is not found."); freeConnections.addElement(conn); notify(); } public void setConnectionSwitch(String on_off) throws ServletException{ try{ if (on_off.equalsIgnoreCase("ON")) openDB(driverName,jdbcURL,username,password); else if (on_off.equalsIgnoreCase("OFF")) closeDB(); } catch(SQLException ex){ throw new ServletException(ex.toString()); } }}package common;import java.lang.*;import java.sql.*;import javax.servlet.*;public class MySqlConn{ private Connection conn; private ResultSet rs; private ResultSetMetaData rsmd; private Statement stmt; private ConnPool connPool; //错误就是在这行产生的 private static final String driverName = "org.gjt.mm.mysql.Driver"; private static final String jdbcURL = "jdbc:mysql://localhost/univessence"; private static final String username = "root"; private static final String password = ""; public MySqlConn(){ conn = null; rs = null; rsmd = null; stmt = null; }//由于字数限制,代码不能完全贴出来}这是该完的 java文件上传在firefox下正常,在IE下出错! jsp中调用.js 文件乱码问题 请问个struts中提交表单并用javascript打开新窗口接受返回页面的问题 关于select对象的问题 100分求一问题解决方案 web.xml中发现找不到类 帮帮忙呀! 怎样将java中取得的数据库数据导到Excel,特急,如能解决马上给分 怎样获得注册用户的登出时间? 请问如何在servlet中对串口进行操作 MiscroStrategy 7 和 Sybase IQ字符编码问题,请进(最经典的提问方式) 求一替换的正则表达式
mySqlConn.java中引用它需要的类
private ConnPool connPool;
改成
private connPoolconnPool;
就可以了
import java.sql.*;
import java.util.*;
import javax.servlet.*;public class ConnPool{
private static final int defaultMaxConnections = 3; private Vector freeConnections;
private Hashtable boundConnections;
private static final String driverName = "org.gjt.mm.mysql.Driver";
private static final String jdbcURL = "jdbc:mysql://localhost/univessence";
private static final String username = "root";
private static final String password = "";
private int maxConnections; public ConnPool(int numConnections){
maxConnections = numConnections;
boundConnections = null;
freeConnections = null;
} public ConnPool(){
this(defaultMaxConnections);
} public void closeDB() throws SQLException{
if (boundConnections != null){
for(Enumeration e = boundConnections.elements();
e.hasMoreElements();){
Connection conn = (Connection)e.nextElement();
conn.close();
}
boundConnections.clear();
boundConnections = null;
}
if (freeConnections != null){
for (Enumeration e = freeConnections.elements();
e.hasMoreElements();){
Connection conn = (Connection)e.nextElement();
conn.close();
}
freeConnections.removeAllElements();
freeConnections = null;
}
} public synchronized Connection getConnection()
throws SQLException{
if (freeConnections == null)
throw new SQLException(
"The connection pool has not been established yet.");
if (boundConnections.get(Thread.currentThread()) != null)
throw new SQLException(
"Cannot get connections over once for this current running thread.");
try{
if (freeConnections.size() == 0)
wait();
}
catch(InterruptedException ex){
throw new SQLException(ex.toString());
}
Connection conn = (Connection)freeConnections.firstElement();
freeConnections.removeElement(conn);
boundConnections.put(Thread.currentThread(),conn);
return conn;
}
public void openDB(String drvName,String url,
String uname,String passwd)
throws SQLException{
try{
boundConnections = new Hashtable(maxConnections);
freeConnections = new Vector(maxConnections);
Class.forName(drvName);
for (int i=0;i<maxConnections;i++)
freeConnections.addElement(
DriverManager.getConnection(url,uname,passwd));
}
catch(Exception ex){
boundConnections = null;
freeConnections = null;
throw new SQLException(ex.toString());
}
} public synchronized void returnConnection()
throws SQLException{
Connection conn =
(Connection)boundConnections.remove(
Thread.currentThread());
if (conn == null)
throw new SQLException(
"The connection which this current running thread got is not found.");
freeConnections.addElement(conn);
notify();
}
public void setConnectionSwitch(String on_off)
throws ServletException{
try{
if (on_off.equalsIgnoreCase("ON"))
openDB(driverName,jdbcURL,username,password);
else if (on_off.equalsIgnoreCase("OFF"))
closeDB();
}
catch(SQLException ex){
throw new ServletException(ex.toString());
}
}}package common;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;public class MySqlConn{
private Connection conn;
private ResultSet rs;
private ResultSetMetaData rsmd;
private Statement stmt;
private ConnPool connPool; //错误就是在这行产生的
private static final String driverName = "org.gjt.mm.mysql.Driver";
private static final String jdbcURL = "jdbc:mysql://localhost/univessence";
private static final String username = "root";
private static final String password = ""; public MySqlConn(){
conn = null;
rs = null;
rsmd = null;
stmt = null;
}//由于字数限制,代码不能完全贴出来}
这是该完的