刘
刘忠平
Unregistered / Unconfirmed
GUEST, unregistred user!
本人最近做一个数据连接 但是不能web.xml中的参数
其中web.xml如下:
。。。
<web-app>
<context-param>
<param-name>driver</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</context-param>
<context-param>
<param-name>url</param-name>
<param-value>jdbcdbc:ISchoolhigh</param-value>
</context-param>
。。。
</web-app>
其中数据连接的文件为DBConnect 代码如下:
package com.js.util;
import java.io.*;
import java.sql.*;
import javax.servlet.ServletConfig;
import com.js.util.*;
public class DBConnect {
private String user = "";
private String password = "";
private String driver = "";
private String url = "";
private Connection conn = null;
private Statement stmt = null;
//创建数据库连接
public void getConn(ServletConfig sc) throws SQLException,IOException
{
driver = sc.getServletContext().getInitParameter("driver");
url = sc.getServletContext().getInitParameter("url");
user = sc.getServletContext().getInitParameter("user");
password = sc.getServletContext().getInitParameter("password");
Class.forName(driver);
DriverManager.getConnectionurl ,user,password);
}
....
}
testjsp.jsp文件为
<%@ page contentType="text/html;
charset=GBK" %>
<%@ page import="java.sql.ResultSet"%>
<jsp:useBean id="dbId" scope="page" class="com.js.util.DBConnExec" />
<html>
<head>
<title>
testjsp
</title>
</head>
<body bgcolor="#ffffff">
<h1>
<%
dbId.getConn(config);
String strSQL = " select * from tbCustomInfo";
ResultSet rs = dbId.selectSQLExec(strSQL);
if (rs == null)
{
out.println("null is null");
}
else
{
out.println(rs.getString(2));
}
%>
</h1>
</body>
</html>
我的环境是jdk1.4 tomcat4.06 其中发现config传进 读不出来driver,url,user,password
所以通过不了 但以前jdk1.3和tomcat4.01下可以
求教各位大虾了
其中web.xml如下:
。。。
<web-app>
<context-param>
<param-name>driver</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</context-param>
<context-param>
<param-name>url</param-name>
<param-value>jdbcdbc:ISchoolhigh</param-value>
</context-param>
。。。
</web-app>
其中数据连接的文件为DBConnect 代码如下:
package com.js.util;
import java.io.*;
import java.sql.*;
import javax.servlet.ServletConfig;
import com.js.util.*;
public class DBConnect {
private String user = "";
private String password = "";
private String driver = "";
private String url = "";
private Connection conn = null;
private Statement stmt = null;
//创建数据库连接
public void getConn(ServletConfig sc) throws SQLException,IOException
{
driver = sc.getServletContext().getInitParameter("driver");
url = sc.getServletContext().getInitParameter("url");
user = sc.getServletContext().getInitParameter("user");
password = sc.getServletContext().getInitParameter("password");
Class.forName(driver);
DriverManager.getConnectionurl ,user,password);
}
....
}
testjsp.jsp文件为
<%@ page contentType="text/html;
charset=GBK" %>
<%@ page import="java.sql.ResultSet"%>
<jsp:useBean id="dbId" scope="page" class="com.js.util.DBConnExec" />
<html>
<head>
<title>
testjsp
</title>
</head>
<body bgcolor="#ffffff">
<h1>
<%
dbId.getConn(config);
String strSQL = " select * from tbCustomInfo";
ResultSet rs = dbId.selectSQLExec(strSQL);
if (rs == null)
{
out.println("null is null");
}
else
{
out.println(rs.getString(2));
}
%>
</h1>
</body>
</html>
我的环境是jdk1.4 tomcat4.06 其中发现config传进 读不出来driver,url,user,password
所以通过不了 但以前jdk1.3和tomcat4.01下可以
求教各位大虾了