首页上一页 1 下一页尾页 6 条记录 1/1页
JSP中调用包出错
发表在JavaWeb图书答疑
2009-03-17
是否精华
是
否
版块置顶:
是
否
小姐/先生:
您好!!!
我在JSP中调用包出错,具体情况如下文件与附件(请到贵公司服务邮箱tmoonbook@sina.com与th_press@263.net查看),此处调用出错造成其下相关调用此文件出错,请速解答,谢谢!!!
package com.tomarsli.dbconn;
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
public class DBConn {
public static synchronized Connection getConnection() throws Exception{
try{
Context initCtx=new javax.naming.InitialContext();
//从Context中lookup数据源
Context envCtx=(Context)initCtx.lookup("java:comp/env");
DataSource ds=(DataSource)envCtx.lookup("jdbc/tomarsli"); // jdbc/mingri
return ds.getConnection();
}
catch(SQLException e){
throw e;
}
catch(NamingException e){
throw e;
}
}
}
package com.tomarsli.dbconn;
import java.sql.*;
import com.tomarsli.dbconn.DBConn;
public class DBResult {
private Connection con;
public DBResult() {
this.con=DBConn.getConnection();
}
/**
* 用于获得执行SQL语句的ResultSet对象
*/
public ResultSet getResult(String sql){
try{
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
return rs;
}
catch(Exception e){}
return null;
}
/**
* 用于执行SQL语句没有返回值
*/
public void doExecute(String sql){
try{
Statement stmt=con.createStatement();
stmt.executeQuery(sql);
}catch(Exception e){}
}
/**
* 用于获得执行SQL语句的PreparedStatement(预处理)对象
*/
public PreparedStatement getPreparedStatement(String sql){
try{
PreparedStatement pstmt=con.prepareStatement(sql);
return pstmt;
}
catch(Exception e){}
return null;
}
/**
* 关闭连接
*/
public void closeCon(){
try{
this.con.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server>
<Listener className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
</GlobalNamingResources>
<Service
name="Catalina">
<Connector
port="8080"
redirectPort="8443"
minSpareThreads="25"
connectionTimeout="20000"
maxSpareThreads="75"
maxThreads="150">
</Connector>
<Connector
port="8009"
redirectPort="8443"
connectionTimeout="-1"
protocol="AJP/1.3">
</Connector>
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost">
<Context path="/erp_jsp " reloadable="true" docBase="erp_jsp">
<Resource name="jdbc/tomarsli" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/tomarsli">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=db_shopping</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>maxActive</name>
<value>1000</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>50</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>50</value>
</parameter>
</ResourceParams>
</Context>
</Host>
</Engine>
</Service>
</Server>
您好!!!
我在JSP中调用包出错,具体情况如下文件与附件(请到贵公司服务邮箱tmoonbook@sina.com与th_press@263.net查看),此处调用出错造成其下相关调用此文件出错,请速解答,谢谢!!!
package com.tomarsli.dbconn;
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
public class DBConn {
public static synchronized Connection getConnection() throws Exception{
try{
Context initCtx=new javax.naming.InitialContext();
//从Context中lookup数据源
Context envCtx=(Context)initCtx.lookup("java:comp/env");
DataSource ds=(DataSource)envCtx.lookup("jdbc/tomarsli"); // jdbc/mingri
return ds.getConnection();
}
catch(SQLException e){
throw e;
}
catch(NamingException e){
throw e;
}
}
}
package com.tomarsli.dbconn;
import java.sql.*;
import com.tomarsli.dbconn.DBConn;
public class DBResult {
private Connection con;
public DBResult() {
this.con=DBConn.getConnection();
}
/**
* 用于获得执行SQL语句的ResultSet对象
*/
public ResultSet getResult(String sql){
try{
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
return rs;
}
catch(Exception e){}
return null;
}
/**
* 用于执行SQL语句没有返回值
*/
public void doExecute(String sql){
try{
Statement stmt=con.createStatement();
stmt.executeQuery(sql);
}catch(Exception e){}
}
/**
* 用于获得执行SQL语句的PreparedStatement(预处理)对象
*/
public PreparedStatement getPreparedStatement(String sql){
try{
PreparedStatement pstmt=con.prepareStatement(sql);
return pstmt;
}
catch(Exception e){}
return null;
}
/**
* 关闭连接
*/
public void closeCon(){
try{
this.con.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server>
<Listener className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
</GlobalNamingResources>
<Service
name="Catalina">
<Connector
port="8080"
redirectPort="8443"
minSpareThreads="25"
connectionTimeout="20000"
maxSpareThreads="75"
maxThreads="150">
</Connector>
<Connector
port="8009"
redirectPort="8443"
connectionTimeout="-1"
protocol="AJP/1.3">
</Connector>
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost">
<Context path="/erp_jsp " reloadable="true" docBase="erp_jsp">
<Resource name="jdbc/tomarsli" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/tomarsli">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=db_shopping</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>maxActive</name>
<value>1000</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>50</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>50</value>
</parameter>
</ResourceParams>
</Context>
</Host>
</Engine>
</Service>
</Server>