JDBCを使用して2枚のExcelシートからデータを読み取りたい。両方のExcelシートに2つのデータソース(システムDSN名)を設定しました.1つのExcelシートからデータを読み取ることができますか?しかし、2番目のExcelシートを接続するにはどうすればよいですか?
1つのExcelシートからデータを読み取るには、以下のコーディングを参照してください。しかし、2番目の接続で2番目のデータソース名を使用するにはどうすればよいですか?あなたがアドバイスしていただけますか。
public class MergeXSLFiles {
public static Connection getConnection() throws Exception {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:Report";
String username = "";
String password = "";
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
}
public static void main(String args[]) throws Exception {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
conn = getConnection();
stmt = conn.createStatement();
String excelQuery = "select * from [Sheet$]";
rs = stmt.executeQuery(excelQuery);
while (rs.next()) {
System.out.println(rs.getString("name") + " " + rs.getString("age"));
}
rs.close();
stmt.close();
conn.close();
}
}
手伝ってくれてありがとう。