js| Connection Database | Problem You can help me look at the following three files (a JSP, two. java), I entered the address in IE, prompted the following error (code should not be wrong, do not know if the problem is set up), look at the high finger teach, appreciate:
D:\Program Files\apache group\tomcat 4.1\work\standalone\localhost\_\shopping\index_jsp.java:44:package Mybean does Not exist
Mybean. Dbconnmanager Connmanager = null;
^
An error occurred at Line:2 in the JSP file:/shopping/index.jsp
Generated servlet error:
D:\Program Files\apache group\tomcat 4.1\work\standalone\localhost\_\shopping\index_jsp.java:46:package Mybean does Not exist
Connmanager = (Mybean. Dbconnmanager) Pagecontext.getattribute ("Connmanager", Pagecontext.application_scope);
^
An error occurred at Line:2 in the JSP file:/shopping/index.jsp
Generated servlet error:
D:\Program Files\apache group\tomcat 4.1\work\standalone\localhost\_\shopping\index_jsp.java:49:package Mybean does Not exist
Connmanager = (Mybean. Dbconnmanager) Java.beans.Beans.instantiate (This.getclass (). getClassLoader (), Mybean. Dbconnmanager ");
^
The following two are connection pools, the following two files are placed in a mybean bag.
public class Dbconnpool {
Number of connections being used
private int using;
Current number of connections available, that is, idle connections
Private vector connections=new vector ();
Maximum number of connections
private int maxconn;
Connection Pool Name
Private String poolname;
Database identification
Private String dbid;
Driver name
Private String drivername;
Database account number
Private String username;
Database Password
Private String passwd;
/* Return the idle connection to the connection pool.
Public synchronized void ReturnConnection (Connection conn) {
Adds the specified connection to the end of the vector
Connections.addelement (conn);
Connect user minus One
using--;
}
/* Get a connection from the connection pool * *
Public synchronized Connection getconnection () {
Connection conn = null; Connection is a class,
Connections is a vector that stores the connection objects that are available for all idle states
if (connections.size () > 0) {
Get the first connection to a list of connections
conn = (Connection) connections.elementat (0);
Connections.removeelementat (0);//Get a connection and remove the connection from the queue.
If this connection is turned off, just continue to fetch,
try {
if (conn.isclosed ())
conn = getconnection ();
}
catch (Exception e) {
E.printstacktrace ();
}
}
If the number of connections actually used is less than the maximum number of connections available, a new connection is added
else if (maxconn = 0 | | Using < MAXCONN) {
When there is no available connection (Maxconn = 0) and the number of connections is not up to the upper limit (using < Maxconn), a new connection is created
Conn=newconnection ();
}
Returns an empty pointer if the number of connections has reached the upper limit
if (conn!=null) {
using++;
}
Return conn;
}
public class Dbconnmanager {
List of connection pool names
Private vector poolnames =new vector ();
List of driver names
Private vector drivernames=new vector ();
List of database identities
Private vector dbids=new vector ();
List of user names
Private vector usernames=new vector ();
User password list
Private vector passwds=new vector ();
List of maximum connections
Private vector maxconns=new vector ();
Connection Pool Queue
Private Hashtable connpools=new Hashtable ();
Public Dbconnmanager () {
Add connection information for an Access database
Poolnames.addelement ("Access");
Drivernames.addelement ("Sun.jdbc.odbc.JdbcOdbcDriver");
Dbids.addelement ("jdbc:odbc:shopping");
Usernames.addelement ("");
Passwds.addelement ("");
Maxconns.addelement ("5");
Add connection information for SQL Server2000 database
Poolnames.addelement ("sqlserver2000");
Drivernames.addelement ("Com.microsoft.jdbc.sqlserver.SQLServerDriver");
Dbids.addelement ("jdbc:microsoft:sqlserver://localhost:1433;databsername=shopping");
Usernames.addelement ("");
Passwds.addelement ("");
Maxconns.addelement ("5");
Connecting MySQL database information
Poolnames.addelement ("MySQL");
Drivernames.addelement ("Org.gjt.mm.mysql.Driver");
Dbids.addelement ("jdbc:mysql://localhost/shopping");
Usernames.addelement ("");
Passwds.addelement ("");
Maxconns.addelement ("5");
Connecting to the Oracle8i/9i database
Poolnames.addelement ("Oracle");
Drivernames.addelement ("Oracle.jdbc.driver.OracleDriver");
Dbids.addelement ("Jdbc:oracle:thin: @localhost: 1521:shopping");
Usernames.addelement ("");
Passwds.addelement ("");
Maxconns.addelement ("5");
Create a connection pool
Createpools ();
}
/* Returns the connection to the specified connection pool.
public void ReturnConnection (String name,connection conn) {
Dbconnpool pool= (Dbconnpool) connpools.get (name);
if (pool!=null)
{
Pool.returnconnection (conn);
}
}
/* Get a connection in a specified connection pool.
Public Connection getconnection (String name) {
Dbconnpool pool= (Dbconnpool) connpools.get (name);
if (pool!=null)
{
return Pool.getconnection ();
}
return null;
}
/* Close all connections *
Public synchronized void Closeconns () {
Enumeration allpools=connpools.elements ();
while (Allpools.hasmoreelements ()) {
Dbconnpool pool= (Dbconnpool) allpools.nextelement ();
Pool.closeconn ();
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.