|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
其实产生见解的过程就是训练自己发现问题,分析问题的能力。根据以上的认识我想谈下传统的学习与通过视频独立学习的优缺点:js|数据|数据库|成绩列位妙手贫苦帮我看上面这三个文件(一个jsp,两个.java),我在IE输出地点时,提醒以下毛病(代码应当没有错,不知是否是设置的成绩),看妙手指教,不堪感谢:
D:ProgramFilesApacheGroupTomcat4.1workStandalonelocalhost\_shoppingindex_jsp.java:44:packagemybeandoesnotexist
mybean.DBConnManagerconnManager=null;
^
Anerroroccurredatline:2inthejspfile:/shopping/index.jsp
Generatedservleterror:
D:ProgramFilesApacheGroupTomcat4.1workStandalonelocalhost\_shoppingindex_jsp.java:46:packagemybeandoesnotexist
connManager=(mybean.DBConnManager)pageContext.getAttribute("connManager",PageContext.APPLICATION_SCOPE);
^
Anerroroccurredatline:2inthejspfile:/shopping/index.jsp
Generatedservleterror:
D:ProgramFilesApacheGroupTomcat4.1workStandalonelocalhost\_shoppingindex_jsp.java:49:packagemybeandoesnotexist
connManager=(mybean.DBConnManager)java.beans.Beans.instantiate(this.getClass().getClassLoader(),"mybean.DBConnManager");
^
//上面这两个是毗连池,上面两个文件都放在一个mybean的包里.
packagemybean;
importjava.sql.*;
importjava.util.*;
publicclassDBConnPool{
//正在利用毗连的数目
privateintusing;
//今朝可用的毗连数,即余暇毗连
privateVectorconnections=newVector();
//最年夜毗连数
privateintmaxconn;
//毗连池名
privateStringpoolname;
//数据库标识
privateStringdbid;
//驱动程序名
privateStringdrivername;
//数据库帐号
privateStringusername;
//数据库暗码
privateStringpasswd;
publicDBConnPool(Stringpoolname,Stringdbid,Stringdrivername,
Stringusername,Stringpasswd,intmaxconn){
this.poolname=poolname;
this.drivername=drivername;
this.dbid=dbid;
this.username=username;
this.passwd=passwd;
this.maxconn=maxconn;
}
/*将余暇毗连前往给毗连池*/
publicsynchronizedvoidreturnConnection(Connectionconn){
//将指定毗连加到向量开端
connections.addElement(conn);
//毗连用户减一
using--;
}
/*从毗连池失掉一个毗连*/
publicsynchronizedConnectiongetConnection(){
Connectionconn=null;//Connection是一个类,
//connections是一个向量,用于存储毗连对象,它所存储是的一切余暇形态的可用毗连
if(connections.size()>0){
//猎取毗连列表的第一个毗连
conn=(Connection)connections.elementAt(0);
connections.removeElementAt(0);//取得一个毗连,并将此毗连从行列中删除.
//假如此毗连已封闭,刚持续猎取,
try{
if(conn.isClosed())
conn=getConnection();
}
catch(Exceptione){
e.printStackTrace();
}
}
//假如实践利用的毗连数小于最年夜毗连数即有可用毗连),就新增添一个毗连
elseif(maxconn==0||using<maxconn){
//云云时无可用毗连(maxconn==0)且毗连数又未到达下限(using<maxconn)),就创立一个新毗连
conn=newConnection();
}
//假如毗连数已到达下限就前往空指针
if(conn!=null){
using++;
}
returnconn;
}
/*创立新的毗连*/
publicConnectionnewConnection(){
Connectionconn=null;
try{
//加载驱动
Class.forName(drivername);
conn=DriverManager.getConnection(dbid,username,passwd);
}catch(Exceptione){
e.printStackTrace();
returnnull;
}
returnconn;
}
/*封闭一切毗连*/
publicsynchronizedvoidcloseConn(){
EnumerationallConnections=connections.elements();
while(allConnections.hasMoreElements()){
Connectionconn=(Connection)allConnections.nextElement();
try{
conn.close();
}catch(SQLExceptione){
e.printStackTrace();
}
}
connections.removeAllElements();
}
}
packagemybean;
importjava.sql.*;
importjava.util.*;
publicclassDBConnManager{
//毗连池名列表
privateVectorpoolnames=newVector();
//驱动程序名列表
privateVectordrivernames=newVector();
//数据库标识列表
privateVectordbids=newVector();
//用户名列表
privateVectorusernames=newVector();
//用户暗码列表
privateVectorpasswds=newVector();
//最年夜毗连数列表
privateVectormaxconns=newVector();
//毗连池行列
privateHashtableconnPools=newHashtable();
publicDBConnManager(){
//增加Access数据库的毗连信息
poolnames.addElement("access");
drivernames.addElement("sun.jdbc.odbc.JdbcOdbcDriver");
dbids.addElement("jdbc:odbc:shopping");
usernames.addElement("");
passwds.addElement("");
maxconns.addElement("5");
//增加SQLServer2000数据库的毗连信息
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");
//毗连Mysql数据库信息
poolnames.addElement("mysql");
drivernames.addElement("org.gjt.mm.mysql.Driver");
dbids.addElement("jdbc:mysql://localhost/shopping");
usernames.addElement("");
passwds.addElement("");
maxconns.addElement("5");
//毗连Oracle8i/9i数据库
poolnames.addElement("oracle");
drivernames.addElement("oracle.jdbc.driver.OracleDriver");
dbids.addElement("jdbc:oracle:thin:@localhost:1521:shopping");
usernames.addElement("");
passwds.addElement("");
maxconns.addElement("5");
//创立毗连池
createPools();
}
/*将毗连前往给由指定的毗连池*/
publicvoidreturnConnection(Stringname,Connectionconn){
DBConnPoolpool=(DBConnPool)connPools.get(name);
if(pool!=null)
{
pool.returnConnection(conn);
}
}
/*失掉一个指定毗连池中的毗连*/
publicConnectiongetConnection(Stringname){
DBConnPoolpool=(DBConnPool)connPools.get(name);
if(pool!=null)
{
returnpool.getConnection();
}
returnnull;
}
/*封闭一切毗连*/
publicsynchronizedvoidcloseConns(){
EnumerationallPools=connPools.elements();
while(allPools.hasMoreElements()){
DBConnPoolpool=(DBConnPool)allPools.nextElement();
pool.closeConn();
}
}
/*创立毗连池*/
privatevoidcreatePools(){
for(inti=0;i<poolnames.size();i++)
{
Stringpoolname=poolnames.elementAt(i).toString();
Stringdrivername=drivernames.elementAt(i).toString();
Stringdbid=dbids.elementAt(i).toString();
Stringusername=usernames.elementAt(i).toString();
Stringpasswd=passwds.elementAt(i).toString();
intmaxconn=0;
try{
maxconn=Integer.parseInt(maxconns.elementAt(i).toString());
}catch(NumberFormatExceptione){
e.printStackTrace();
}
DBConnPoolpool=newDBConnPool(poolname,drivername,dbid,username,
passwd,maxconn);
connPools.put(poolname,pool);
}
}
}
上面这个是主页面.JSP文件
<%@pagecontentType="text/html;charset=GBK"%>
<%@pageimport="java.sql.*"%>
<jsp:useBeanid="connManager"scope="application"class="mybean.DBConnManager"/>
<html>
<head>
<title>
购物商城首页
</title>
</head>
<bodybgcolor="#B0C4DE">
<center><h1>接待会见本购物商城</h1></center>
<%
//ConnectionconnA=connManager.getConnection("access");
ConnectionconnS=connManager.getConnection("sqlserver2000");
if(connS==null)
{
%>
数据库正忙,请稍后再会见
<%
}
//StatementstmtA=connA.createStatement();
StatementstmtS=connS.createStatement();
%>
<%
Stringsql="select*fromuserinfo";
ResultSetrs=stmtS.executeQuery(sql);
while(rs.next())
{
%>
<tr>
<td><%=rs.getString("username")%></td>
<td><%=rs.getString("userpass")%></td>
</tr>
<%
}
rs.close();
stmtS.close();
connManager.returnConnection("sqlserver2000",connS);
%>
</body>
</html>
net程序员的大部门代码都靠控件拖拽完成的,虽然java也有,但是无论从美观和速度上都没发和.net比。java程序员都是代码完成的,所以java程序员常戏称.net程序员是操作员,呵呵。 |
|