Consultor Eletrônico



Kbase 19329: A java example on how connect to SQL-92 Database through JDB
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   21/08/2003
Status: Verified

GOAL:

A java example on how connect to SQL-92 Database through JDBC

FACT(s) (Environment):

Progress 9.1x

FIX:

// This example should be saved as TestJDBC.java


import java.sql.*;

class TestJDBC
{
   public static void main (String args [])
      throws SQLException, ClassNotFoundException
   {
      //Here you load the JDBC driver needed.
      //You will have to replace it with your own drivername

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

      // After this, you need to connect using the URL for your
      // database
      // For more information in the URL please see the
      // Progress JDBC driver Guide.

      Connection conn = DriverManager.getConnection ("jdbc:jdbcprogress:T:localhost:3001:sports","test","test");

      //From the connection, you have to create a statement context.

      Statement stmt = conn.createStatement ();

      //From the statement you can create a resultset containing the
      //results of a query. In this case it is a list of all names
      //returned from the customer table.

      ResultSet rset = stmt.executeQuery ("select name from PUB.customer");

      //Now you need to loop the resultset and print the results
      while (rset.next()){
           System.out.println(rset.getString(1));
      }
  }
}


Note :
The above example assumes your Database is called "sports" and started with the parameters -S 3001 -H localhost. It also assumes "test/test" user is created in the Database and is having required privileges to query "customer"'s table.