0
我試圖與使用Eclipse IDE JSP程序postgre DATABSE連接,ClassNotFound的異常:org.postgresql.Driver從[模塊「deployment.ValidateUser.war:主」,從服務模塊加載]
我得到這個錯誤:
"java.lang.ClassNotFoundException: org.postgresql.Driver from [Module "deployment.ValidateUser.war:main" from Service Module Loader]".
我已經把我的項目所需的jar文件,即使我得到classnotfound異常錯誤。
<%@page import="com.uservalidation.FarwordNames"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<%-- Imports --%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%-- HTTP header --%>
<%response.addHeader("Cache-Control","no-cache");
response.addHeader("Pragma","no-cache");
response.addHeader("Expires","0");
%>
<%-- Variables that will be written --%>
<%
String fname = request.getParameter("fname");
String mname = request.getParameter("mname");
String lname = request.getParameter("lname");
String dob = request.getParameter("dob");
String addr = request.getParameter("addr");
%>
<%-- Creating new staff account - writing --%>
<%
try{
Class.forName("org.postgresql.Driver");
String conURL= "jdbc:postgresql://192.168.1.157:5432/MIPSUITE_DEV";
Connection con = DriverManager.getConnection(conURL,"mipsuitedev01","mipsuitedev01");
Statement st = con.createStatement();
//int status = st.executeUpdate("insert into users(fname,mname,lname,dob,address) values('"+fname+"',"+mname+"','"+lname+"','"+dob+"','"+addr+"')");
/* if(status>0){
out.println("Update sucessful");
}
else{
out.println("Update unsuccessful");
} */
st.close();
con.close();
}
catch(Exception e){
out.println(e);
}
%>
</body>
</html>
如果您使用的是Eclipse,右鍵單擊特定的jar文件,將它放到您的項目中,然後轉到Build Path,然後單擊Add to Build Path –