no argument: Statement
one or more argument: PreparedStatement
public class Outer {
public static void main(String[] args) throws Exception{
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/data/Sample");
try(con) {
System.out.println(con);
String sql = "select * from firsttable where id<=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1,20);
ResultSet rs = ps.executeQuery();
ResultSetMetaData md = ps.getMetaData();
int columnCount = md.getColumnCount();
System.out.println("col count : " + columnCount);
try(rs) {
int colIndex = 0;
while(rs.next()){
System.out.print(rs.getString("ID") + ":");
System.out.println(rs.getString("NAME"));
for(int i=0;i<columnCount;i++) {
colIndex = i + 1;
System.out.println(" "+ md.getTableName(colIndex) + ":" +
md.getColumnName(colIndex) + ":" +
rs.getString(colIndex));
}
}
}
}
}
}
org.apache.derby.client.net.NetConnection@17d0685f
org.apache.derby.client.net.NetConnection@17d0685f
col count : 2
10:TEN
FIRSTTABLE:ID:10
FIRSTTABLE:NAME:TEN
20:TWENTY
FIRSTTABLE:ID:20
FIRSTTABLE:NAME:TWENTY