ajax跟servlet做一个异步验证,异常java.lang.ClassNotFoundException:oracle.jdbc.driver.Oracle

肉肉包 2014-12-09 09:49:45
ajax跟servlet做一个异步验证,异常java.lang.ClassNotFoundException:oracle.jdbc.driver.Oracle

初学者,不懂得怎么解决这个问题,调试了一下代码发现:Class.forName(DRIVER); 这句代码以及之后的代码不执行,其他的代码都是正确的,怀疑是jar驱动包的问题,重新下载一个导入项目中还是不行,求解决!
PS:数据库的连接是正常的!

...全文
142 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zml6308 2014-12-10
  • 打赏
  • 举报
回复
几个方面: 1.缺少驱动包! 2.包不对 3.包没有加载到项目中
licip 2014-12-10
  • 打赏
  • 举报
回复
你是连接oracle数据库吧。 驱动包没有加。
HelloBarreat 2014-12-10
  • 打赏
  • 举报
回复
代码贴上来呀
肉肉包 2014-12-10
  • 打赏
  • 举报
回复
引用 3 楼 zml6308 的回复:
几个方面:
1.缺少驱动包!
2.包不对
3.包没有加载到项目中
这样不是就加载了驱动包了吗?
肉肉包 2014-12-10
  • 打赏
  • 举报
回复
这是servelt源码:自己的写的主类是没有问题的
package myServlet;
import java.io.IOException;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

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




public class CheckServlet extends HttpServlet{
	public static final String DRIVER="oracle.jdbc.driver.OracleDriver";
	public static final String URL="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
	public static final String USER="scott";
	public static final String PASS="simon";
	
	public static void main(String[] args) {
		Connection connection=null;
		PreparedStatement statement = null;
		ResultSet set=null;
		System.out.println(true);
		try {
			Class.forName(DRIVER);
			
			connection=DriverManager.getConnection(URL,USER,PASS);
			System.out.println("@@@@@@@@@@@@@@");
			statement=connection.prepareStatement("select * from ajaxmember where mid=?");
			statement.setString(1, "simon");
			set=statement.executeQuery();
			while (set.next()) {
				System.out.println(set.getString(1));
				
				
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}finally{
			try {
				set.close();
				statement.close();
				connection.close();
			} catch (Exception e2) {
				// TODO: handle exception
			}		
		}
		
	}
	public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException{
		req.setCharacterEncoding("GBK");
		resp.setContentType("text/html");
		PrintWriter out=resp.getWriter();
		String  userid=req.getParameter("userid");
		System.out.println(userid);
		String sql="select count(mid) from ajaxmember where mid=?" ;
		System.out.println(sql);
		Connection connection=null;
		PreparedStatement statement = null;
		ResultSet set=null;	
		try {	
			Class.forName(DRIVER);
			connection=DriverManager.getConnection(URL,USER,PASS);	
			System.out.println("*****************");
			statement=connection.prepareStatement(sql);
			statement.setString(1, userid);
			set=statement.executeQuery();
			while (set.next()) {
				if(set.getInt(1)>0){
					System.out.println("false");
					out.println("false");				
				}else {
					System.out.println("true");
					out.println("true");
				}
			}
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}finally{
			try {
				statement.close();
				set.close();
			} catch (Exception e2) {
				e2.printStackTrace();
				// TODO: handle exception
			}								
		}	
	}
	public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException{
		this.doGet(req, resp);	
	}
}

52,792

社区成员

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

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