Kbase P113920: How to connect to Progress database from a Java application in OpenEdge version 10.1?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/16/2008 |
|
Status: Verified
GOAL:
How to connect to OpenEdge database from a Java application?
GOAL:
Java code example on how to connect and get results from a OpenEdge database?
GOAL:
Using the new type 4 JDBC driver
FACT(s) (Environment):
OpenEdge SQL Category: JDBC Drivers
OpenEdge 10.1x
FIX:
The CLASSPATH:
Set the correct CLASSPATH environment variable to let the application find the Java classes.
The CLASSPATH environment variable must contain the archives containing the classes for the version 10.1x database JDBC driver.
These are: OPENEDGE.JAR; BASE.JAR and UTIL.JAR located within the JAVA subdirectory of the OpenEdge installation directory.
Example for Windows:
SET CLASSPATH=d:\OpenEdge101A\java\openedge.jar;d:\OpenEdge101A\java\base.jar;d:\OpenEdge101A\java\util.jar
Example for UNIX:
CLASSPATH=/usr1/OpenEdge101a/java/openedge.jar:/usr1/OpenEdge101a/java/base.jar:/usr1/OpenEdge101a/java/util.jar;
export CLASSPATH
The Progress Version 10.1x JDBC driver name:
com.ddtek.jdbc.openedge.OpenEdgeDriver
The database connection URL:
jdbc:datadirect:openedge://<hostname>:<port number>;databaseName=<name of the database>
<hostname> needs to be replaced with the hostname the database is running on
<port number> needs to be replaced with the service port the database server is listening
Example URL for the sports2000 database running on host localhost port 6789:
jdbc:datadirect:openedge://localhost:6789;databaseName=sports2000
Example code:
Executable against sports2000 database with username pub and password pub created with the Data Administration tool and started for listening on port 6789 with the command
PROSERVE sports2000 -S 6789 from within ProEnv:
import java.sql.*;
public class JdbcTest
{
public static void main (String args [])
{
try
{
Class.forName ("com.ddtek.jdbc.openedge.OpenEdgeDriver");
System.out.println("Driver loaded");
Connection con = DriverManager.getConnection("jdbc:datadirect:openedge://localhost:6789;databaseName=sports2000","pub","pub");
System.out.println("Connected");
Statement stmt = con.createStatement();
System.out.println("Statement created");
ResultSet rs = stmt.executeQuery("select name from customer");
System.out.println("ResultSet : \n");
while (rs.next())
{
System.out.println(rs.getString(1));
}
rs.close();
stmt.close();
con.close();
}
catch (Exception x) {x.printStackTrace();}
}
}
The code above has to be saved as file JdbcTest.java
Before running the code compile it using the command:
javac JdbcTest.java
To execute it:
java JdbcTest