jdbc-db2 - 提取完整记录
jdbc-db2 - extract full record
我试图从 DB2 table 中提取数据。我想知道是否有一种方法可以在不指定各个列名称的情况下从 ResultSet 打印整个记录。
我的代码:
import java.sql.*;
public class Ftp {
public static void main(String[] args) {
String url = "jdbc:db2://mvshost:4456/SQA_SYSTEM";
String user = "xxxxx";
String password = "yyyyyy";
Connection con;
PreparedStatement stmt;
ResultSet rs;
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
con = DriverManager.getConnection(url, user, password);
con.setAutoCommit(false);
stmt = con.prepareStatement("SELECT EMP FROM IDATDMK.GREEN");
rs = stmt.executeQuery();
while (rs.next()) {
String EMP = rs.getString("EMP");
System.out.println("EMP from DB2 = " + EMP);
}
rs.close();
stmt.close();
con.commit();
con.close();
}
catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
}
如果我将查询写成 Select * from IDATDMK.GREEN
,我如何在不指定各个列名称的情况下在 while 循环中打印整个记录。我在 table.
中有 80 多列
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
while(rs.next(){
for (int i = 1; i <= columnsNumber; i++) {
if (i > 1) System.out.print("\n");
String columnValue = rs.getString(i);
System.out.print(columnValue) }}
我试图从 DB2 table 中提取数据。我想知道是否有一种方法可以在不指定各个列名称的情况下从 ResultSet 打印整个记录。
我的代码:
import java.sql.*;
public class Ftp {
public static void main(String[] args) {
String url = "jdbc:db2://mvshost:4456/SQA_SYSTEM";
String user = "xxxxx";
String password = "yyyyyy";
Connection con;
PreparedStatement stmt;
ResultSet rs;
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
con = DriverManager.getConnection(url, user, password);
con.setAutoCommit(false);
stmt = con.prepareStatement("SELECT EMP FROM IDATDMK.GREEN");
rs = stmt.executeQuery();
while (rs.next()) {
String EMP = rs.getString("EMP");
System.out.println("EMP from DB2 = " + EMP);
}
rs.close();
stmt.close();
con.commit();
con.close();
}
catch (Exception e) {
System.out.println("Exception: " + e);
}
}
}
}
如果我将查询写成 Select * from IDATDMK.GREEN
,我如何在不指定各个列名称的情况下在 while 循环中打印整个记录。我在 table.
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
while(rs.next(){
for (int i = 1; i <= columnsNumber; i++) {
if (i > 1) System.out.print("\n");
String columnValue = rs.getString(i);
System.out.print(columnValue) }}