Advertisement
ossiejhmoore

Untitled

Nov 14th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. String driver = props.getProperty("jdbc.dest.driver");
  2. String url = props.getProperty("jdbc.dest.url");
  3. String user = props.getProperty("jdbc.dest.username");
  4. String pass = props.getProperty("jdbc.dest.password");
  5. user = StringUtils.isNullOrEmpty(user) ? null : user;
  6. pass = StringUtils.isNullOrEmpty(pass) ? null : pass;
  7.  
  8. Class.forName(driver);
  9. Connection con;
  10. if ((user == null) && (pass == null)) {
  11.     con = DriverManager.getConnection(url);
  12. } else {
  13.     con = DriverManager.getConnection(url, user, pass);
  14. }
  15. PreparedStatement stmtTestConnection = con.prepareStatement("select dataid ,name from DTREE where dataid = ?");
  16. stmtTestConnection.setInt(1, 2000);
  17. ResultSet rs = stmtTestConnection.executeQuery();
  18. while(rs.next()) {
  19.     System.out.printf("dataid: %s, name: %s%n", rs.getInt(1), rs.getString(2));
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement