0

So I'm trying to connect to a database file MSAccess. Here is the code:

public class DAOCarLoader implements CarLoader {

    List < Owner > owners = new ArrayList < Owner > ();
    Connection con;
    Statement st;
    ResultSet rs;


    public DAOCarLoader() {

        loadData1();
    }

    public void loadData1() {
        try {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            String db = "jdbc:ucanaccess://C:/Users/Anjelo/Desktop/CarTable2.mdb";
            con = DriverManager.getConnection(db);
            st = con.createStatement();
            String sql = "select * from Table1";
            rs = st.executeQuery(sql);
            while (rs.next()) {
                String brand = rs.getString("CarBrand");
                String carnumber = rs.getString("CarNum");
                int year = rs.getInt("CarYear");
                String fname = rs.getString("OwnerName");
                String egn = rs.getString("OwnerEGN");
                System.out.println("TEST");
                System.out.println(brand + " " + carnumber + " " + year + " " + fname + " " + egn);
            }
        } catch (Exception ex) {

            System.out.println(ex.getMessage());
        }
    }

    @Override
    public List < Owner > loadData() {
        // TODO Auto-generated method stub
        return null;
    }

    public static void main(String[] args) {

        new DAOCarLoader();

    }
}

But everytime I run the program the only thing that shows in the console is:

net.ucanaccess.jdbc.UcanaccessDriver

What is causing the problem? Thank you in advance for your time.

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
Cr1ms0nStraY
  • 81
  • 1
  • 2
  • 10
  • For details on how to set up UCanAccess see [Manipulating an Access database from Java without ODBC](http://stackoverflow.com/q/21955256/2144390). – Gord Thompson Jun 07 '15 at 21:07

1 Answers1

2

Try downloading http://sourceforge.net/projects/ucanaccess/files/UCanAccess-2.0.9.5-bin.zip/download and configure your build path adding the jar files into the lib folder from downloaded files.

@Edit

Your problem could be related with missing dependencies in your project. The driver class (net.ucanaccess.jdbc.UcanaccessDriver) may not exist in your build path. Change the exception catching for a better debugging:

System.out.println(ex.getMessage());

to

ex.printStackTrace();
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – JNYRanger Jun 07 '15 at 19:24
  • @JNYRanger sorry about the link-only anwser, i've edited and tried to improve the answer. – Alisson Vieira Jun 07 '15 at 19:41