外行请教jsp数据库链接500错误.
偶不懂JSP,公司JSP程序员走了,让偶配置JSP站点.花了1周才把环境搞好.现在又出500错误.请各路神仙帮忙.
数据库链接代码:
package cn.com.dateConn;
import java.sql.*;
public class DateConnSql {
private static Connection conn = null;
public static Connection getInstance() {
if(conn == null)
new DateConnSql();
return conn;
}
private DateConnSql() {
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
} catch (
ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
conn=DriverManager.getConnection( "jdbc:odbc:mydata ");
} catch (
SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
root cause
java.lang.NullPointerException cn.com.dateConn.PageConn.executeQuery(PageConn.java:21)
//第21行就是conn=DriverManager.getConnection( "jdbc:odbc:mydata ");
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.
--------------------------------------------
Apache Tomcat/5.5.12
------解决方案--------------------得配置ODBC mydata
------解决方案--------------------conn=DriverManager.getConnection( "jdbc:odbc:mydata ");
mydata是什么?数据库连接的原理是下面这个:
Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@192.168.1.1:1521:ora9i ", "name ", "password ");
这是连接oracle的,jdbc:oracle:thin:@是固定的,然后跟着ip地址,然后是用户名和密码
------解决方案--------------------从错误信息上来看,你的错误不是这个类的,应该是别的类的,可能 pageConn中的executeQuery方法出了问题
------解决方案--------------------我给你写了个类你试一下,希望能帮到你
import java.sql.*;
public class DB {
private Connection con=null;
private Statement stmt=null;
private ResultSet rs=null;
//url= "jdbc:odbc:first ";
//Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
//con=DriverManager.getConnection(url, "sa ", " ");
String DBDriver= "sun.jdbc.odbc.JdbcOdbcDriver ";
String url= "jdbc:odbc:Test ";
public DB()
{
try
{
Class.forName(DBDriver);
}
catch (Class
NotFoundException e)
{
System.out.println( "opendb: "+e.getMessage());
}
}
public ResultSet excuteQuery(String sql)