0

I'm trying to get some data from a .mdb database, this is the code:

package com.java.myapp;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;

public class MyClass {

    public static void main(String[] args) {

        Connection connect = null;
        Statement s = null;

        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            connect =  DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};" +
                    "DBQ=mydatabase.mdb;uid=;pwd=;");

            s = connect.createStatement();

            String Name = "Win";

            String sql = "SELECT * FROM  customer WHERE Name LIKE '%" + Name + "%' ";

            ResultSet rec = s.executeQuery(sql);

            while((rec!=null) && (rec.next()))
            {
                System.out.print(rec.getString("CustomerID"));
                System.out.print(" - ");
                System.out.print(rec.getString("Name"));
                System.out.print(" - ");
                System.out.print(rec.getString("Email"));
                System.out.print(" - ");
                System.out.print(rec.getString("CountryCode"));
                System.out.print(" - ");
                System.out.print(rec.getFloat("Budget"));
                System.out.print(" - ");
                System.out.print(rec.getFloat("Used"));
                System.out.println("");
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            s.close();
            connect.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

but I'm getting this error:

Unable to load JdbcOdbc library:java.sql.SQLException: Unable to load JdbcOdbc library
Exception:java.sql.SQLException: No suitable driver
Exception:java.lang.NullPointerException

Im trying this jar in AIX, the database has not password. it seems like im missing a library, but I don't know that library in particular. Thanks for any help.

Jota
  • 16,103
  • 7
  • 54
  • 89
  • Running Java 8 by any chance? It doesn't have the ODBC bridge driver anymore. http://stackoverflow.com/questions/14229072/removal-of-jdbc-odbc-bridge-in-java-8 – Gimby Dec 01 '14 at 15:53
  • Im using NetBeans 8.0.1 JDK: 1.6 – user3314345 Dec 01 '14 at 15:59
  • 1
    You might be interested in the related question [here](http://stackoverflow.com/q/21955256/2144390). – Gord Thompson Dec 01 '14 at 16:11
  • Thx for the response, but im getting the error : Exception:java.sql.SQLException:No suitable driver, in the line: connect=DriverManager.getConnection("jdbc:ucanaccess://banchile.mdb"); Im not working in windows, is linux AIX, mabye thats the problem.. thanks – user3314345 Dec 01 '14 at 18:21

0 Answers0