Sample AS400 JDBC class.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class AS400Query {
public static void main(String[] args) {
ArrayList<String> arl = new ArrayList<String>();
try {
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
Connection con =
DriverManager.getConnection("jdbc:as400://<server>",
"<user>", "<password>");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT <col> FROM <table>");
while (rs.next()){
arl.add(rs.getString(1));
}
rs.close();
for(String s : arl){
String sql = " UPDATE <table> SET COL= " + s;
System.out.println(sql);
stmt.execute(sql);
}
stmt.close();
con.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment