简体   繁体   中英

Exception in thread “main” java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:/Users/gfas1/Desktop/st.accdb

So I'm trying to set up the connection in access database but otherwise fails. I have imported the ucanaccess 5 files already and I'm confused why this doesn't work. Here are the jars

public class Access {

public static void main(String[] args) throws ClassNotFoundException, SQLException {
    // TODO Auto-generated method stub


        Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:/Users/gfas1/Desktop/st.accdb");
        Statement stment = conn.createStatement();
        String qry = "SELECT * FROM Students";

        ResultSet rs = stment.executeQuery(qry);
        while(rs.next())
        {
            String id    = rs.getString("ID") ;
            String fname = rs.getString("Name");

            System.out.println(id + fname);
        }
    }



} 

JDBC driver should be loaded and you should have driver jar in your classpath

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

In this case driver registers itself and Java knows how to handle those database connection.

also see http://ucanaccess.sourceforge.net/site.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM