JDBC Driver with Sample Code - Forum - OpenEdge RDBMS - Progress Community

JDBC Driver with Sample Code

 Forum

JDBC Driver with Sample Code

  • I am trying to establish a connection between JAVA program and Progress V10.1a database using JDBC Driver. I heard that there is a change in Class.forName() and DriverManager.getConnection().

    Can anybody tell me how to connect JDBC through Progress Database.?

    Amrit Mishra

  • // CLASSPATH=$DLC/java/jdbc.jar (or progress.jar), export CLASSPATH

    // LIBPATH=$DLC/lib:$LIBPATH; export LIBPATH

    import java.lang.*;

    import java.math.*;

    import java.io.PrintStream;

    import java.sql.Connection;

    import java.sql.DatabaseMetaData;

    import java.sql.DriverManager;

    import java.sql.ResultSet;

    import java.sql.*;

    import java.util.*;

    public class shipment_sync_v10{

    protected static final PrintStream o = System.out;

    public static void main(String[] args) {

    try {

    java.util.TimeZone zone = java.util.TimeZone.getTimeZone("Etc/GMT-8");

    TimeZone tz = TimeZone.getTimeZone("Hongkong");

    Properties prop = new Properties();

    String url = "jdbc:datadirect:openedge://" + "testserver:3050;databaseName="

    + "ver10";

    byte urlBytes[] = new byte;

    System.out.println("Defaultl url=" + url);

    String userid = "xxxx";

    String passwd = "root";

    int cnt = 0;

    byte[] passwdBytes = new byte;

    byte[] useridBytes = new byte;

    StringBuffer sb = new StringBuffer();

    // version 9 Class.forName("com.progress.sql.jdbc.JdbcProgressDriver");

    Class.forName("com.ddtek.jdbc.openedge.OpenEdgeDriver");

    prop.put("user", userid);

    prop.put("password", passwd);

    java.sql.Connection con = DriverManager.getConnection(url,userid,passwd);

    DatabaseMetaData dma = con.getMetaData();

    o.println("\nConnected to " + dma.getURL());

    o.println("Driver " + dma.getDriverName());

    o.println("Version " + dma.getDriverVersion());

    Statement stmt = con.createStatement();

    String sSTMT = new String("select count(*) from pub.shipment_sync");

    System.out.println("SQL-Statement : " + sSTMT + "\n");

    ResultSet rset = stmt.executeQuery(sSTMT);

    while (rset.next()){

    cnt = cnt + 1;

    //System.out.println(rset.getString(1));

    }

    System.out.println("Number of records=" + cnt);

    }

    catch (java.lang.Exception ex) {

    ex.printStackTrace(); }

    }

    }