package kcwdb2test;
import com.ibm.as400.access.AS400JDBCConnectionPoolDataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class KcwDB2TestDev {
public static void main(String[] args) {
Connection dbConnection = null;
String cipher="AES";
String cipherdomain="INTRANET";
String host="1.2.3.4";
String dblibrary="WWWDLIB";
String login="not-encoded";
String user="kcw";
String password="12345678";
try {
AS400JDBCConnectionPoolDataSource datasource = new AS400JDBCConnectionPoolDataSource(host, user, password);
datasource.setLibraries(dblibrary);
dbConnection = datasource.getConnection();
// Sample 1
String query = "SELECT DMNDMCDEC,USRFINAMC,USRLANAMC,USREMPIDN,USRUSIDNN FROM ASWDLIB.WWUSR10 where DMNDMCDEC='INTRANET'";
Statement statement = dbConnection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while(resultSet.next()) {
System.out.println(
resultSet.getString(1) + " " +
resultSet.getString(2) + " " +
resultSet.getString(3) + " " +
resultSet.getInt(4) + " " +
resultSet.getInt(5));
}
statement.close();
// Sample 2
PreparedStatement statement2 = dbConnection.prepareStatement(
"SELECT DMNDMCDEC,USRFINAMC,USRLANAMC,USREMPIDN,USRUSIDNN FROM ASWDLIB.WWUSR10 where DMNDMCDEC=?"
);
statement2.setString(1, "INTRANET");
ResultSet resultSet2 = statement2.executeQuery();
while(resultSet2.next()) {
System.out.println(
resultSet2.getString(1) + " " +
resultSet2.getString(2) + " " +
resultSet2.getString(3) + " " +
resultSet2.getInt(4) + " " +
resultSet2.getInt(5));
}
statement2.close();
dbConnection.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
}
No comments:
Post a Comment