找不到 jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb 的合适驱动程序
No suitable driver found for jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb
我不得不面对这个错误:
No suitable driver found for jdbc:ucanaccess://C:\Users\Asim
Iqbal\Documents\PersonInfo.accdb
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
在我的 JSP 项目中。但是当我分别运行PersonDAO.java
的时候,就正常了。但是,通过使用 Bean,我不得不面对这种类型的错误。这些文件如下。
PersonDAO.java
import java.util.*;
import java.sql.*;
import java.io.*;
public class PersonDAO implements Serializable {
private PreparedStatement stmt;
public ArrayList pList;
String url="jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb";
Connection conn = DriverManager.getConnection(url);
public PersonDAO() throws SQLException{
establishConnection();
}
private void establishConnection() throws SQLException
{
String url1="jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb";
conn = DriverManager.getConnection(url1);
}
public ArrayList getPerson(String name) throws SQLException {
PersonInfo pInfo=new PersonInfo();
pList=new ArrayList();
String sql="SELECT * FROM Person WHERE name=?";
stmt=conn.prepareStatement(sql);
stmt.setString(1,name);
ResultSet rs=stmt.executeQuery();
String add,n;
String p;
while(rs.next()){
n=rs.getString("Name");
add=rs.getString("Address");
p=rs.getString("PhoneNumber");
pInfo.setName(n);
pInfo.setAddress(add);
pInfo.setpNumber(p);
pList.add(pInfo);
}
return pList;
}
}
saveperson.jsp
</head>
<jsp:useBean id="pDAO" class="Person.PersonDAO" scope = "request" />
<jsp:useBean id="personBean" class="Person.PersonInfo" scope="request"/>
<jsp:setProperty name="personBean" property="name" param="name"/>
<jsp:setProperty name="personBean" property="address" param="address"/>
<jsp:setProperty name="personBean" property="pNumber" param="pNumber"/>
<%
pDAO.setPerson(personBean);
%>
<center>
<h1>You have successfully add the record!</h1>
<h4>
<a href="index.html" > Add another Person Record </a> <br>
<br><br>
<a href="searchperson.jsp" > Search Person </a>
</h4>
</center>
请告诉我哪里做错了..
您必须将 ucanaccess jar 添加到类路径并调用 Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
,然后再尝试打开连接(一次就足够),以便 DriverManager 找到具有该 url 的驱动程序,请参阅 here.
我不得不面对这个错误:
No suitable driver found for jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
在我的 JSP 项目中。但是当我分别运行PersonDAO.java
的时候,就正常了。但是,通过使用 Bean,我不得不面对这种类型的错误。这些文件如下。
PersonDAO.java
import java.util.*;
import java.sql.*;
import java.io.*;
public class PersonDAO implements Serializable {
private PreparedStatement stmt;
public ArrayList pList;
String url="jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb";
Connection conn = DriverManager.getConnection(url);
public PersonDAO() throws SQLException{
establishConnection();
}
private void establishConnection() throws SQLException
{
String url1="jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb";
conn = DriverManager.getConnection(url1);
}
public ArrayList getPerson(String name) throws SQLException {
PersonInfo pInfo=new PersonInfo();
pList=new ArrayList();
String sql="SELECT * FROM Person WHERE name=?";
stmt=conn.prepareStatement(sql);
stmt.setString(1,name);
ResultSet rs=stmt.executeQuery();
String add,n;
String p;
while(rs.next()){
n=rs.getString("Name");
add=rs.getString("Address");
p=rs.getString("PhoneNumber");
pInfo.setName(n);
pInfo.setAddress(add);
pInfo.setpNumber(p);
pList.add(pInfo);
}
return pList;
}
}
saveperson.jsp
</head>
<jsp:useBean id="pDAO" class="Person.PersonDAO" scope = "request" />
<jsp:useBean id="personBean" class="Person.PersonInfo" scope="request"/>
<jsp:setProperty name="personBean" property="name" param="name"/>
<jsp:setProperty name="personBean" property="address" param="address"/>
<jsp:setProperty name="personBean" property="pNumber" param="pNumber"/>
<%
pDAO.setPerson(personBean);
%>
<center>
<h1>You have successfully add the record!</h1>
<h4>
<a href="index.html" > Add another Person Record </a> <br>
<br><br>
<a href="searchperson.jsp" > Search Person </a>
</h4>
</center>
请告诉我哪里做错了..
您必须将 ucanaccess jar 添加到类路径并调用 Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
,然后再尝试打开连接(一次就足够),以便 DriverManager 找到具有该 url 的驱动程序,请参阅 here.