I want to read the data from two excel sheets using JDBC. So i have setup two data sources(system DSN names) for both excel sheets.Now i’m able to read the data from one excel sheet ? But how to connect the second the excel sheet ?
Please see the below coding to read the data from one excel sheet.But how to use second data source name in the second connection ? Can you please advise.
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();
}
}
Thanks for help.
Just execute the other query to get the results from the next sheet