Consultor Eletrônico



Kbase 17758: Apptivity: Java Example to Test JDBC Connections
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   1/27/2005
Status: Unverified

GOAL:

How to Verify if your JDBC connection works with Progress Apptivity?

FACT(s) (Environment):

Apptivity

FIX:

The following example must be modified for your particular database situation.  It is provided as a reference to how it could be done.  For more information on JDBC, please refer to a JDBC manual.  This example verifies mainly whether or not your driver and URL parameters are correct.

Save the following example as Example.java:

import java.sql.*;
class Example
{
   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 ("openlink.jdbc.Driver");

      // After this, you need to connect using the URL for your
      // database

      Connection conn = DriverManager.getConnection ("YOUR URL");

      //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 customer");

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