Consultor Eletrônico



Kbase 19122: Sample Java Program to Access Progress SQL92 Engine via JDBC
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   3/25/2005
Status: Verified

GOAL:

A sample Java program to access the SQL-92 engine via JDBC.

FACT(s) (Environment):

Progress 9.x

FIX:

The program assumes that there is a database server for a running Sports2000 database that uses port 2500. The example uses a user "dba1" with a password of "password".

NOTE: For the SDK version of the SQL-92 engine in Version 9.0A and 9.0B, use the following values for driver and URL:

driver = "com.progress.sql.jdbc.ProgressDriver"
URL = "jdbc:progress:T:localhost:2500:sports2000"

Create a file Java2Progress.java and paste the program bellow.
To compile the code use: $JDKHOME/bin/javac Java2Progress.java
To execute the compiled code: $JDKHOME/bin/java Java2Progress

The Java Program:
import java.sql.*;


public class Java2Progress

{

public static void main( String[] args )

{

String driver = "com.progress.sql.jdbc.JdbcProgressDriver";

String URL = "jdbc:jdbcprogress:T:localhost:2500:sports2000";

String username = "dba1";

String password = "password";

Connection con = null;

DatabaseMetaData dmd = null;

ResultSet rs = null;


try

{

Class.forName( driver );

con = DriverManager.getConnection( URL, username, password );


PreparedStatement stmt = con.prepareStatement (

" SELECT name FROM pub.customer ");


System.out.println( "Connected to " + URL );

System.out.println("SELECT name FROM pub.customer ");


System.out.println("============================");


rs = stmt.executeQuery();

while (rs.next()) {

String s = rs.getString(1);

System.out.println(s);

}

rs.close();

}

catch (SQLException ex) {

System.out.println ("\n*** SQLException caught ***\n");

while (ex != null) {

System.out.println ("SQLState: " + ex.getSQLState ());

System.out.println ("Message: " + ex.getMessage ());

System.out.println ("Vendor: " + ex.getErrorCode ());

ex = ex.getNextException ();

System.out.println ("");

}

}

catch ( Throwable excp ) {

&nb.sp; excp.printStackTrace ();

}

}

}
.