非常奇怪的问题

bigglacier 2004-01-05 06:40:20
我编写了一个数据库连接类,使用test.java文件,在jdk编译,全部正常。
可是我把.class移到tomcat中,使用jsp访问,抛出
java.lang.NullPointerException
at test.test.testDBOperator.executeQueryInt(testDBOperator.java:110)
at org.apache.jsp.test2$jsp._jspService(test2$jsp.java:94)

错误。
全部代码如下,非常简单。
大虾们,帮帮我吧,我快被折磨完蛋了。
...全文
66 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigglacier 2004-01-06
  • 打赏
  • 举报
回复
====================================
既然报
NoClassDefFoundError: oracle/jdbc/driver/OracleDriver
这个错,说明没有找到Oracle的驱动啊。

估计还是你没把驱动放到Tomcat 的lib/extend目录下
==========================================
问题解决了,我把class12.zip放在jdk的lib/extend目录下就可以了,看来是没有找到类包。
可他没报import错误。
可我通过电脑属性classpath已经指定了,
在tomcat中的lib目录下装了oracle的驱动文件,
而且在tomcat的catalina.bat也已经制定了,
也通过web-inf目录下的lib文件夹也放了,
看来对于类包的一些知识我还不够了解,
谁能详细的解释一下关于类包的指定,以及这几个方法那个优先权最高等,
在线等待,结贴,给分(我已经快没分了)55555555555555。。。
chenyongcsdn 2004-01-05
  • 打赏
  • 举报
回复
不是已经报NullPointerException了吗!
你的testDBOperator.java ,110行出错,你去看一下就知道了!
dropship 2004-01-05
  • 打赏
  • 举报
回复
还有了,你要定位编译后生成的servlet文件,位于work/standalone下面,看看那一行出的异常
wangnanwn 2004-01-05
  • 打赏
  • 举报
回复
上面那位仁兄提到的空格是不能有的?
还有你在tomcat中的lib目录下装了oracle的驱动文件吧?
寒冬 2004-01-05
  • 打赏
  • 举报
回复
你先按照楼上说的,改改试试
stonecsdn 2004-01-05
  • 打赏
  • 举报
回复
url= "jdbc:oracle:thin:@192.9.200.36:1521:123 ";//123后面根了一个空格
private static String user= "system ";
private static String password= "manager ";
是不是这几行结尾中空格的问题?
bigglacier 2004-01-05
  • 打赏
  • 举报
回复
全部代码如下,非常简单,就是数据库访问:

testDBOperator.java
------------------------------
package test.test;

import java.io.*;
import java.sql.*;
import java.util.*;


import oracle.jdbc.driver.*;

final public class testDBOperator{

private final static boolean FLAG_CHECKIN = true; // wether use checkIn sql convert
private final static boolean FLAG_CHECKOUT = true; // wether use checkOut sql convert

private final static int SUCCEED = 0; // Operation succeed
private final static int FAILURE = -1; // Operation failure

private static String url= "jdbc:oracle:thin:@192.9.200.36:1521:123 ";
private static String user= "system ";
private static String password= "manager ";
// private java.sql.Connection conn = null;
//private java.sql.Statement stmt = null;
//private java.sql.ResultSet rs = null;
private ResultSetMetaData meta = null;
private int columnCount;
/**
/* construct function
*/
public testDBOperator() {

}
final public static String checkIn(String a_strInput) throws Exception
{
if (a_strInput == null) return " ";

try{
if (FLAG_CHECKIN)
return new String(a_strInput.getBytes(), "GB2312 ");
else
return a_strInput;

} catch(Exception e) {
throw new Exception( "Error Occur in checkIn. "+ e.getMessage());
}
}
/**
* Convert db string to page string
* @param string : input string
* @return string converted
*/
final public static String checkOut(String a_strInput) throws Exception
{
if (a_strInput == null) return " ";

try{
if (FLAG_CHECKOUT)
return new String(a_strInput.getBytes( "GB2312 "));
else
return a_strInput;

}catch(Exception e){
throw new Exception( "Error Occur in checkOut. "+ e.getMessage());
}
}
final public static int executeQueryInt (String sql)
throws SQLException,Exception
{
int rtn = FAILURE;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn=DriverManager.getConnection(url,user,password);
//mps use
//conn = DbConnectionManager.getConnection();

stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) rtn = rs.getInt(1);
//Logged program for debug
//Mpslog.record (SystemProperty.INFO,sql);
//System.out.println(rtn);
//rtn = stmt.executeUpdate(sql);
// stmt.close();
// conn.close();
} catch (SQLException sqle) {
conn.rollback();
throw new SQLException ( "Error Occur in executeUpdate. " + sqle.getMessage());

} catch (Exception ex) {
conn.rollback();
throw new Exception ( "Error Occur in executeUpdate. " + ex.getMessage());

} finally {
if (stmt != null) stmt.close();
//stmt.close();
//if (!conn.isClosed() ) conn.close();
if (conn != null && !conn.isClosed()) conn.close();
//conn.close();
}
return rtn;
}
}
-----------------------
test.jsp
----------------------
<html >
<head >
<%@ page language = "java " % >
<%@ page import= " java.io.* " % >
<%@ page import = " java.sql.* " % >
<%@ page import = "test.test.* " % >

<%@ page import = "java.util.* " % >


<title >Untitled Document </title >
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " >
<style type= "text/css " >
<!--
font {
font-size: 9pt;
}
p {
font-size: 9pt;
}
td {
font-size: 9pt;
}
-- >
</style >

</head >

<body bgcolor= "#FFFFFF " text= "#000000 " leftmargin= "0 " topmargin= "0 " marginwidth= "0 " marginheight= "0 " >

<%
try {
//String sql = " ";
//String sqlcount = " ";
//sql = "select sysdate from dual ";
String sql= "select count(a1) from test ";
testDBOperator op = new testDBOperator();
int tmp = op.executeQueryInt(sql);

out.println( " Testing executeQueryString -- sysdate : " + tmp);

} catch (SQLException sqle){
sqle.printStackTrace();

} catch (Exception ex) {
ex.printStackTrace();

}

% >

</body >

</html >
----------------------------

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧