0

I am developing a Spring Boot application that polls data from a legacy ODBC data source and inserts it into a MS SQL Server database.

enter image description here

I need to connect to DSN that is using Progress OpenEdge driver.

My R&D code to connect to DSN looks like this:

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

public class JdbcDemo
{
    public static void main(String args[]) throws Exception
    {
        try
        {
            String query = "SELECT Name,Description,Qty,Cost FROM Stock";

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:DSN_Name");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next())
            {
                String name = rs.getString("Name");
                String desc = rs.getString("Description");
                int qty = rs.getInt("Qty");
                float cost = rs.getFloat("Cost");
                System.out.println(name + ", " + desc + "\t: " + qty + "\t@ $" + cost);
            }
            con.close();
        }
        catch (Exception e)
        {
            System.err.println(e);
        }

    }
}

But it throws java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver error when run. I did some Googling and found this is no longer supported. How can then I connect to this ODBC data source? I am using Java 17.

Ram
  • 1,225
  • 2
  • 24
  • 48
  • This is your answer: https://stackoverflow.com/a/19741242/2851311 – hfontanez May 16 '22 at 16:40
  • @hfontanez It tells that I need specific ODBC driver. Is there no other way ? – Ram May 16 '22 at 16:44
  • This is the only way I know of. – hfontanez May 16 '22 at 16:46
  • 1
    Other duplicate: [Replacement for JDBC-ODBC Bridge](https://stackoverflow.com/questions/13358217/replacement-for-jdbc-odbc-bridge). That said, it would make more sense to use the [Microsoft SQL Server JDBC driver](https://github.com/Microsoft/mssql-jdbc) to connect to SQL Server, and the Progress [OpenEdge JDBC driver](https://www.progress.com/jdbc/openedge) for OpenEdge. (As an aside, it is very confusing that in one sentence you say you want to connect to a MS SQL Server database and in another sentence that you want to connect to Progress OpenEdge.) – Mark Rotteveel May 16 '22 at 19:16

1 Answers1

0

java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver exception comes in Java 8 because it has removed the JDBC ODBC bridge driver class "sun.jdbc.odbc.jdbcodbcdriver" from JDK and JRE. This class is required to connect any database using Object database connectivity driver e.g. Microsoft Access, but unfortunately, you cannot use it from JDK 8 onward. In order to solve this error, just use the Jackcess library or a commercial driver like HXTT. Normally, in pre-Java 8 world, java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver error comes when you try to connect to the Microsoft Access database from Java using JDBC and JDBC ODBC bridge driver is not available in the classpath.

Read more: https://javarevisited.blogspot.com/2015/07/how-to-solve-javalangclassnotfoundexception-sun.jdbc.odbc.jdbcodbcdriver.html#ixzz7TTDxvBZp

We can still use JDBC-ODBC Bridge in Java 8 (Java 17 not tested) too, we can always pull the driver from JDK 7: Removal of JDBC ODBC bridge in java 8

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Sibin Rasiya
  • 1,132
  • 1
  • 11
  • 15