Advertisement
Guest User

Untitled

a guest
May 17th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public static void main(String[] args) {
  2. // TODO code application logic here
  3. Connection conn = null;
  4.  
  5. try{
  6. String driverName = "oracle.jdbc.driver.OracleDriver";
  7. Class.forName(driverName);
  8. String serverName = "localhost";
  9. String serverPort = "1521";
  10. String sid = "XE";
  11. String url = "jdbc:oracle:thin:@" + serverName + ":" + serverPort + ":" + sid;
  12. String username = "SYSTEM";
  13. String password = "Batman1997";
  14. conn = DriverManager.getConnection(url, username, password);
  15. System.out.println("Sucesso");
  16. }catch(ClassNotFoundException e){
  17. System.out.println("could not find the DB driver " + e.getMessage());
  18. }catch(SQLException e){
  19. System.out.println("Could not connect to the database " + e.getMessage());
  20. }
  21.  
  22. //vai tentar buscar os dados
  23. try{
  24. System.out.println("rfr");
  25. Statement st = conn.createStatement();
  26. ResultSet rs = st.executeQuery("select * from TestingTable");
  27. while(rs.next()){
  28. int num = rs.getInt(1);
  29. String name = rs.getString(2).toString();
  30. System.out.println("" + num + " " + name);
  31. }
  32.  
  33. }catch(Exception e){
  34. e.printStackTrace();
  35. }
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement