No suitable driver found for jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb

北城以北 提交于 2019-12-24 09:02:55

问题


I have to face this error:

No suitable driver found for jdbc:ucanaccess://C:\Users\Asim Iqbal\Documents\PersonInfo.accdb org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)

in my JSP project. But when I run PersonDAO.java separately, it works properly. But, by using Bean I have to face this type of error. These files are as followed.

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>

Please tell me where I am doing wrong..


回答1:


You must add the ucanaccess jar to the classpath and call Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); before you try to open the connection (once is enough) for the DriverManager to find the driver with that url, see here.



来源:https://stackoverflow.com/questions/31741879/no-suitable-driver-found-for-jdbcucanaccess-c-users-asim-iqbal-documents-per

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!