Connection string for java to connect openedge database

Posted by dnessapkota10 on 02-May-2012 06:43

Hi all,

I have sucessfully connected the progress database using Netbeans IDE 7.1 and also executed the sql query from execute command option provided by Netbeans. But the problem is while I am going to connect and execute sql query using Java open database connection codes it throws error as,

run:
May 02, 2012 5:22:34 PM test.TeST main
SEVERE: null
java.lang.ClassNotFoundException: com.progress.sql.jdbc.JdbcProgressDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at test.TeST.main(TeST.java:33)

BUILD SUCCESSFUL (total time: 0 seconds)

Here is my connection code,

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author dsapkota
*/
public class TeST {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // TODO code application logic here
            Connection conn = null;
            String url = "jdbc:datadirect:openedge://localhost:15003/";
            String dbName = "sports";
            String driver = "com.ddtek.jdbc.openedge.OpenEdgeDriver";
            String userName = "dsapkota";
            String password = "";
           
            String v_name = null;
            try {
               
                Class.forName(driver).newInstance();
            } catch (InstantiationException ex) {
                Logger.getLogger(TeST.class.getName()).log(Level.SEVERE, null, ex);
                System.out.println("EX: " +ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(TeST.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                conn = DriverManager.getConnection(url+dbName,userName,password);
            } catch (SQLException ex) {
                Logger.getLogger(TeST.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.out.println("Connected to the database");
           
            //SQL query here
            ResultSet resultSet = null;
            String query = "select ccustomer.ccusm from PUB.ccustomer where ccusn = 1" ;
            PreparedStatement st = null;
            try {
                st = conn.prepareStatement(query);
            } catch (SQLException ex) {
                Logger.getLogger(TeST.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                resultSet = st.executeQuery(query);
            } catch (SQLException ex) {
                Logger.getLogger(TeST.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
               
                while(resultSet.next()){ 
                  v_name = resultSet.getString("ccusm");
                  System.out.println(v_name);
               }
            } catch (SQLException ex) {
                Logger.getLogger(TeST.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TeST.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

I have also attached the screen shot of progress database which was sucessfully connected from services->database view of Netbeans.

Any solution?

Thanks in advance,

Dinesh

All Replies

Posted by FrankHilhorst on 25-May-2012 08:45

It just so happens I am working on a project where I did this.

It got this error and it was because of these resaons:

  • Did not include openedge.jar as an external library
  • did not reference the correct driver

Here is the code I used to establish the connection from Java.

I have a problem getting a ResultSet to be an updatable resultset.

I you figure that oiut ley me know.

import java.io.*;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.Statement;

import java.sql.ResultSet;

import java.sql.SQLException;

private static String jdbcDriver = "com.ddtek.jdbc.openedge.OpenEdgeDriver";

private static String jdbcConnDbUrl = "jdbc:datadirect:openedge://localhost:3093;databaseName=Queue";

try {

Class.forName(jdbcDriver);

conn = DriverManager.getConnection(jdbcConnDbUrl,username,password);

conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);

conn.setAutoCommit(true);

conn.setReadOnly(false);

} catch (ClassNotFoundException e) {

e.printStackTrace();

} catch (SQLException e) {

e.printStackTrace();

}

Posted by dnessapkota10 on 28-May-2012 01:01

Thanks a lot Frank.

This thread is closed