Test.java
text/plain
import java.sql.*;
import java.io.*;
public class Test
{
public static void main(String [] args)
{
if(args.length!=3) {
System.err.println("Usage: <URL> <UID> <PWD>");
System.exit(1);
}
Test app=new Test();
try {
app.go(args[0],args[1],args[2]);
}
catch(Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
private void go(String url,String uid,String pwd) throws Exception
{
Class.forName("org.postgresql.Driver");
Connection connection=DriverManager.getConnection(url,uid,pwd);
connection.setAutoCommit(false);
PreparedStatement s=connection.prepareStatement("select mykey from mytest");
ResultSet rs=s.executeQuery();
while(rs.next()) {
PreparedStatement s2=connection.prepareStatement("select * from mytest where mykey=?");
s2.setLong(1,rs.getLong(1));
ResultSet rs2=s2.executeQuery();
while(rs2.next()) {
System.out.println(rs2.getLong(1) + " " + rs2.getString(2));
}
rs2.close();
s.close();
}
rs.close();
s.close();
connection.commit();
connection.close();
}
}