Guest User

Untitled

a guest
Dec 18th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. public class OracleJdbcTest
  2. {
  3. String driverClass = "oracle.jdbc.driver.OracleDriver";
  4.  
  5. Connection con;
  6.  
  7. public void init(FileInputStream fs) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException
  8. {
  9. Properties props = new Properties();
  10. props.load(fs);
  11. String url = props.getProperty("db.url");
  12. String userName = props.getProperty("db.user");
  13. String password = props.getProperty("db.password");
  14. Class.forName(driverClass);
  15.  
  16. con=DriverManager.getConnection(url, userName, password);
  17. }
  18.  
  19. public void fetch() throws SQLException, IOException
  20. {
  21. PreparedStatement ps = con.prepareStatement("select SYSDATE from dual");
  22. ResultSet rs = ps.executeQuery();
  23.  
  24. while (rs.next())
  25. {
  26. // do the thing you do
  27. }
  28. rs.close();
  29. ps.close();
  30. }
  31.  
  32. public static void main(String[] args)
  33. {
  34. OracleJdbcTest test = new OracleJdbcTest();
  35. test.init();
  36. test.fetch();
  37. }
  38. }
Add Comment
Please, Sign In to add comment