Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5.  
  6. public class Main {
  7.  
  8. public static Connection getConnection() throws Exception {
  9. String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
  10. String url = "jdbc:odbc:excelDB";
  11. String username = "yourName";
  12. String password = "yourPass";
  13. Class.forName(driver);
  14. return DriverManager.getConnection(url, username, password);
  15. }
  16.  
  17. public static void main(String args[]) throws Exception {
  18. Connection conn = null;
  19. Statement stmt = null;
  20. ResultSet rs = null;
  21.  
  22. conn = getConnection();
  23. stmt = conn.createStatement();
  24. String excelQuery = "select * from [Sheet1$]";
  25. rs = stmt.executeQuery(excelQuery);
  26.  
  27. while (rs.next()) {
  28. System.out.println(rs.getString("FirstName") + " " + rs.getString("LastName"));
  29. }
  30.  
  31. rs.close();
  32. stmt.close();
  33. conn.close();
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement