请问tomcat连接sql2000异常
请教tomcat连接sql2000错误
1、在tomcat的server.xml中配置连接池代码
2、index.jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.wsy.selectsql,java.util.*,com.wsy.news,com.wsy.product,java.sql.*"%>
<jsp:useBean id="sql" class="com.wsy.selectsql" scope="page"/>
3、在index.jsp同目录中建立com\wsy,并在wsy文件夹中放入下面两个文件
connsqlserver.java
selectsql.java
运行后显示错误
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /WebRoot/index.jsp(3,5) The value for the useBean class attribute com.wsy.selectsql is invalid.
怎么回事?谢谢!!
------解决思路----------------------
看看编译的路径是不是有问题
1、在tomcat的server.xml中配置连接池代码
<Context path="/net" docBase="net" debug="5" reloadable="true" corssContext="true">
<Resource
name="jdbc/ConnectionPool"
auth="Container"
type="javax.sql.DataSource"
maxActive="20"
maxIdle="5"
maxWait="10000"
username="sa"
password=""
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_net"/>
</Context>
</Host>
2、index.jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.wsy.selectsql,java.util.*,com.wsy.news,com.wsy.product,java.sql.*"%>
<jsp:useBean id="sql" class="com.wsy.selectsql" scope="page"/>
3、在index.jsp同目录中建立com\wsy,并在wsy文件夹中放入下面两个文件
connsqlserver.java
package com.wsy;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class connsqlserver {
/**
* @param args
*/
private static Connection cn = null;
private void getConnection() {
if (cn != null) {
return;
}
Context ctx;
try {
ctx = new InitialContext();
DataSource ds = (DataSource) ctx
.lookup("java:comp/env/jdbc/ConnectionPool");
cn = ds.getConnection();
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return;
}
public ResultSet executeQuery(String sql) {
if (cn == null)
getConnection();
try {
return cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE).executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
}
}
public int executeUpdate(String sql) {
if (cn == null)
getConnection();
try {
return cn.createStatement().executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
return -1;
} finally {
}
}
public void close() {
try {
cn.close();
} catch (SQLException e) {
e.printStackTrace();
}finally{
cn = null;
}
}
}
selectsql.java
package com.wsy;
import java.sql.*;
import java.util.*;
import java.text.*;
public class selectsql {
public static ResultSet rs;
public static StringTrans s;
public static connsqlserver connsqlserver=new connsqlserver();
/*
* 关于tb_usertable表的操作
*/
public static Collection getRet(){
Collection ret=new ArrayList();
try{
connsqlserver connsqlserver=new connsqlserver();
String sql="select * from tb_usertable";
rs=connsqlserver.executeQuery(sql);
while(rs.next()){
String names=rs.getString("name");
String passwords=rs.getString("password");
user user=new user();
user.setName(names);
user.setPassword(passwords);
ret.add(user);
}
}
catch(Exception e){
e.printStackTrace();
}
connsqlserver.close();
return ret;
}
运行后显示错误
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /WebRoot/index.jsp(3,5) The value for the useBean class attribute com.wsy.selectsql is invalid.
怎么回事?谢谢!!
------解决思路----------------------
看看编译的路径是不是有问题