Kbase 17755: Apptivity: How to access the database from the server JDBC
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
Apptivity: How to access the database from the server JDBC
DRAFT COPY - Currently under review and edit.
INTRODUCTION:
=============
This entry contains a simple example showing the steps needed to
access the database from a Server Event using existing DataConnections
WHY YOU NEED TO KNOW THIS:
===========================
People who want to write certain programs to check or update the
database and think this takes too long executing from the client can
write a server event that performs the same task using a direct JDBC
set of commands.
PROCEDURAL APPROACH:
====================
For this to work, you will have to define a serverRequest to perform
the needed SQL functions.
When creating the ServerRequest, one of the parameters referenced is t
he abServer handle. Pass this handle to the new method you are
to perform the needed actions.
The method could look something like the following:
public abVector MakeUpdate(abServer thisserver , abVector arg)
{
Statement stmt;
ResultSet result;
String statement = new String("UPDATE state SET region = 'WEST'")
int count = 0;
abVector returnValue = new abVector();
try{
abServer tototo = thisserver; //This will get the Server context
abConnection tititi = tototo.getConnection("dcProgress");
Connection conn = tititi.getConnection(abConnection.UPDATE);
System.out.println("I got the Connection for Update");
// From this moment on it is all standard JDBC to perform the update
stmt = conn.createStatement();
count = stmt.executeUpdate(statement);
System.out.println("Did the update for all regions to WEST");
}
catch(Exception totototo){
totototo.printStackTrace();
}
return(returnValue);
}
This should update all the region fields from a certain table called
state to WEST using a defined DataConnection called dcProgress.
Remember that if the autocommit is set to off then the commit needs to
be done manually.
For more information on JDBC I advise to get a good book on the Topic.
TBO
03/11/98
Progress Software Technical Support Note # 17755