This was a just a demonstration to show how to retrieve data from database through extended rules without using SQL map.
Presession rules:
object jdbc_object,jdbcConnection,connection;
string[100] poolName, table, column, sql_string;
integer i;
object stm, res;
sql_string = "select FIRST_NAME from STUDENT where STD_NO = '3'";
// Conn object for obtaining connection
//create 3rd party jar (package.class)
jdbc_object= new("mynewjavadatabase.MyNewJavaDataBase");
jdbcConnection= new("com.sterlingcommerce.woodstock.util.frame.jdbc.Conn");
connection = jdbcConnection.getConnection("db2Pool");
i = 1;
Extended rules:
string[255] sql_result_pl, pl;
sql_result_pl = "a";
pl = "FIRST_NAME";
stm = jdbc_object.getPreparedStatement(sql_string,connection);
res = jdbc_object.getResultSet(stm);
jdbc_object.executeNext(res);
sql_result_pl = jdbc_object.getData(res, pl);
#input = sql_result_pl; //here we can get first name from database.
Java Code in MyNewJavaDataBase class:
package mynewjavadatabase;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.sterlingcommerce.woodstock.util.frame.jdbc.JDBCService;
public class MyNewJavaDataBase {
Connection con = null;
PreparedStatement stm = null;
ResultSet res = null;
String result=null;
public Connection getConnection(String poolName)
{
try
{
Connection con=JDBCService.getConnection(poolName);
return con;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public PreparedStatement getPreparedStatement(String SQLstatement, Connection con) {
try{
stm = con.prepareStatement(SQLstatement);
return stm;
} catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public ResultSet getResultSet(PreparedStatement stm) {
try{
res = stm.executeQuery();
return res;
} catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public int getRowCount(ResultSet res, String SQLstatement)
{
int i = 0;
try {
stm = con.prepareStatement(SQLstatement);
res = stm.executeQuery();
res.next();
i = res.getInt("CNT");
return i;
} catch (Exception ex){
ex.printStackTrace();
return i;
}
}
public void executeNext(ResultSet res)
{
try {
res.next();
} catch (Exception ex){
ex.printStackTrace();
}
}
public String getData(ResultSet res, String columnName)
{
try {
//res.next();
result = res.getString(columnName);
} catch (Exception ex){
ex.printStackTrace();
}
return result;
}
public void closePreparedStatement(PreparedStatement stm) {
try{
stm.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void closeResultSet(ResultSet res) {
try{
res.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void closeConnection(Connection con)
{
try
{
if (con != null && !con.isClosed())
{
con.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void freeConn(String poolName,Connection con)
{
try
{
if (con != null && !con.isClosed())
{
//con.close();
JDBCService.freeConnection(poolName,con);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Required jars:
install_foundation.jar
platform_afc.jar
Please correct me if did any thing wrong.
Presession rules:
object jdbc_object,jdbcConnection,connection;
string[100] poolName, table, column, sql_string;
integer i;
object stm, res;
sql_string = "select FIRST_NAME from STUDENT where STD_NO = '3'";
// Conn object for obtaining connection
//create 3rd party jar (package.class)
jdbc_object= new("mynewjavadatabase.MyNewJavaDataBase");
jdbcConnection= new("com.sterlingcommerce.woodstock.util.frame.jdbc.Conn");
connection = jdbcConnection.getConnection("db2Pool");
i = 1;
Extended rules:
string[255] sql_result_pl, pl;
sql_result_pl = "a";
pl = "FIRST_NAME";
stm = jdbc_object.getPreparedStatement(sql_string,connection);
res = jdbc_object.getResultSet(stm);
jdbc_object.executeNext(res);
sql_result_pl = jdbc_object.getData(res, pl);
#input = sql_result_pl; //here we can get first name from database.
Java Code in MyNewJavaDataBase class:
package mynewjavadatabase;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.sterlingcommerce.woodstock.util.frame.jdbc.JDBCService;
public class MyNewJavaDataBase {
Connection con = null;
PreparedStatement stm = null;
ResultSet res = null;
String result=null;
public Connection getConnection(String poolName)
{
try
{
Connection con=JDBCService.getConnection(poolName);
return con;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public PreparedStatement getPreparedStatement(String SQLstatement, Connection con) {
try{
stm = con.prepareStatement(SQLstatement);
return stm;
} catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public ResultSet getResultSet(PreparedStatement stm) {
try{
res = stm.executeQuery();
return res;
} catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public int getRowCount(ResultSet res, String SQLstatement)
{
int i = 0;
try {
stm = con.prepareStatement(SQLstatement);
res = stm.executeQuery();
res.next();
i = res.getInt("CNT");
return i;
} catch (Exception ex){
ex.printStackTrace();
return i;
}
}
public void executeNext(ResultSet res)
{
try {
res.next();
} catch (Exception ex){
ex.printStackTrace();
}
}
public String getData(ResultSet res, String columnName)
{
try {
//res.next();
result = res.getString(columnName);
} catch (Exception ex){
ex.printStackTrace();
}
return result;
}
public void closePreparedStatement(PreparedStatement stm) {
try{
stm.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void closeResultSet(ResultSet res) {
try{
res.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void closeConnection(Connection con)
{
try
{
if (con != null && !con.isClosed())
{
con.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void freeConn(String poolName,Connection con)
{
try
{
if (con != null && !con.isClosed())
{
//con.close();
JDBCService.freeConnection(poolName,con);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Required jars:
install_foundation.jar
platform_afc.jar
Please correct me if did any thing wrong.