java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
用的Myeclipse10.7编的javaweb项目,要连接oracle数据库,oracle的jdbc的jar包我已导入,不过是通过buildpath-->addexte...
用的Myeclipse10.7编的javaweb项目,要连接oracle数据库,oracle的jdbc的jar包我已导入,不过是通过buildpath-->add external jars导入的。它存放的位置也是在refereced libraries里。在变了个java的类试下连接没问题。可就是在网页上运行时就报java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver。就是在下面代码中要跳转到login_success.jsp时。
也曾试过将oracle驱动手工粘贴到项目中的web-inf/lib下,也不好使。求帮助。
下面是代码:
<%!
public static final String dbdriver = "oracle.jdbc.OracleDriver";
public static final String dburl = "jdbc:oracle:thin:@localhost:1521:orcl";
public static final String dbuser = "train";
public static final String dbpwd = "train";
%>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean flag = false;
String name = null;
%>
<%
try{
Class.forName(dbdriver);
conn = DriverManager.getConnection(dburl,dbuser,dbpwd);
String sql = "select username from login_user where username=? and pwd=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, request.getParameter("username"));
pstmt.setString(2, request.getParameter("pwd"));
rs = pstmt.executeQuery();
if(rs.next()){
name = rs.getString(1);
flag = true;
}
} catch (Exception e) {
System.out.println(e);
} finally {
try {
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {}
}
%>
<%
if (flag){
%>
<jsp:forward page="login_success.jsp">
<jsp:param value="<%=name%>" name="uname"/>
</jsp:forward>
<%
} else {
%>
<jsp:forward page="login_failed.jsp"/>
<%
}
%> 展开
也曾试过将oracle驱动手工粘贴到项目中的web-inf/lib下,也不好使。求帮助。
下面是代码:
<%!
public static final String dbdriver = "oracle.jdbc.OracleDriver";
public static final String dburl = "jdbc:oracle:thin:@localhost:1521:orcl";
public static final String dbuser = "train";
public static final String dbpwd = "train";
%>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean flag = false;
String name = null;
%>
<%
try{
Class.forName(dbdriver);
conn = DriverManager.getConnection(dburl,dbuser,dbpwd);
String sql = "select username from login_user where username=? and pwd=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, request.getParameter("username"));
pstmt.setString(2, request.getParameter("pwd"));
rs = pstmt.executeQuery();
if(rs.next()){
name = rs.getString(1);
flag = true;
}
} catch (Exception e) {
System.out.println(e);
} finally {
try {
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {}
}
%>
<%
if (flag){
%>
<jsp:forward page="login_success.jsp">
<jsp:param value="<%=name%>" name="uname"/>
</jsp:forward>
<%
} else {
%>
<jsp:forward page="login_failed.jsp"/>
<%
}
%> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询