个人觉得遇到奇怪的问题

tubage408 2007-08-03 08:19:51
我昨天写了段链接oracle数据库的测试代码。具体情况是这样的:我先写好了链接类,又写了个带main方法的类进行测试,能把我要的结果打出来。但是我又弄了个servlet,从页面请求查数据库。但是总是提示java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver。不知道是什么原因。
补充:所需要的驱动我已经放到了项目中,而且版本也没问题。

有遇到相同情况的朋友或者知道原因的朋友,告诉我一下原因,谢谢!!!
...全文
191 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tubage408 2007-08-03
  • 打赏
  • 举报
回复
晕,又不可以了。奇怪了!!??##
下面是个servlet:
package com.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SplitPage extends HttpServlet {

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
List list = new ArrayList();
User user = null;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String sql="select * from t_user";
ResultSet rs = null;
Statement stmt = null;
ConnectionDB connection = new ConnectionDB();
try {

stmt = connection.connDB();

rs = stmt.executeQuery(sql);

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while(rs.next()){
user = new User();
user.setUserName(rs.getString("userName"));
user.setPassword(rs.getString("password"));
user.setAddress(rs.getString("address"));
list.add(user);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("users",user);
request.getRequestDispatcher("resultPage.jsp").forward(request,response);
}

}
tubage408 2007-08-03
  • 打赏
  • 举报
回复
知道为什么了,谢谢各位
tubage408 2007-08-03
  • 打赏
  • 举报
回复
链接DB的类:
package com.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnectionDB {

private Connection conn;
//ResultSet rs;
private Statement stmt;
public Statement connDB( ) throws SQLException{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:database","system","dbuser");
stmt = conn.createStatement();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return stmt;
}

}


带main方法的测试类:

package com.test;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestDB {

/**
* @param args
*/
static String sql="select * from t_user";
static ResultSet rs;
public static void main(String[] args) {
// TODO Auto-generated method stub
ConnectionDB connection = new ConnectionDB();
try {
Statement stmt = connection.connDB();
rs = stmt.executeQuery(sql);

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while(rs.next()){
String userName = rs.getString("userName");
System.out.println(userName);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}


servlet:

不能飞的肥燕 2007-08-03
  • 打赏
  • 举报
回复
你把代码贴出来啊
否则大家只能猜测你的问题
tubage408 2007-08-03
  • 打赏
  • 举报
回复
kingdom_seu()???还在不?帮我解释一下,出现这种情况是为什么呀??
tubage408 2007-08-03
  • 打赏
  • 举报
回复
已经不报那个错误了,但是现在报java.sql.SQLException: 关闭的语句: next;我的程序写的没问题呀!!这是为什么呀??
kingdom_seu 2007-08-03
  • 打赏
  • 举报
回复
你把驱动包放到$\Program Files\Java\jre1.6.0_01\lib\ext
下面试试

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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