Menu

No suitable driver found Error

Help
2017-11-17
2017-11-19
  • Michael Schwamborn

    Hi,
    Im trying to run my code to access a simple DB but its giving me this error :

    Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:ucanaccess:\data\TestDB.accdb
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at mainProgram.Back_End.getDBData(Back_End.java:214)
        at mainProgram.Back_End.main(Back_End.java:84)
    

    Here's my code:

    package mainProgram;
    
    import java.io.*;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.sql.*;
    import java.util.Scanner;
    import net.ucanaccess.*;
    
    import org.apache.commons.io.*;
    
    import com.itextpdf.text.*;
    import com.itextpdf.text.pdf.PdfPCell;
    import com.itextpdf.text.pdf.PdfPTable;
    import com.itextpdf.text.pdf.PdfWriter;
    
    import interfaces.iRL; 
    
    public class Back_End {
    
        public static void main(String[] args) throws SQLException, ClassNotFoundException {
            getDBData();
    
        }
    
        public static void getDBData() throws SQLException, ClassNotFoundException {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
    
                Connection conn=DriverManager.getConnection(
                    "jdbc:ucanaccess:\\data\\TestDB.accdb");
    
            Statement s;
    
                s = conn.createStatement();
    
            ResultSet rs;
    
                rs = s.executeQuery("SELECT [FirstName] FROM [Test]");
    
                 System.out.println(rs.getString(1));
    
            while (rs.next()) {
                System.out.println(rs.getString(1));
    
            }
    
        }
    
    }
    

    Im Using Eclipse and here is where my Libraries are located and where the DB is located.
    https://ibb.co/cUovTR
    https://ibb.co/dUz28R
    Note: The reason why im using "jdbc:ucanaccess:\data\TestDB.accdb" instead of "jdbc:ucanaccess://C:...\data\TestDB.accdb" is beacuse this java project is being shared over GitHub.

     

    Last edit: Michael Schwamborn 2017-11-18
  • Gord Thompson

    Gord Thompson - 2017-11-18

    The UCanAccess connection URL must always begin with jdbc:ucanaccess://, followed by the path to the database file.

    For a relative path (e.g., data\TestDB.accdb) that would be

    jdbc:ucanaccess://data/TestDB.accdb

     

    Last edit: Gord Thompson 2017-11-18
  • Michael Schwamborn

    Ok It's working now
    Thank you!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.