Advertisement
Guest User

Untitled

a guest
Feb 27th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. public void onClick(View v) {
  2. // create our mysql database connection
  3. try {
  4. System.out.println("Loading driver...");
  5. Class.forName("com.mysql.jdbc.Driver");
  6. System.out.println("Driver loaded!");
  7. } catch (ClassNotFoundException e) {
  8. throw new RuntimeException("Cannot find the driver in the classpath!", e);
  9. }
  10. try
  11. {
  12. Connection conn;
  13. conn = DriverManager.getConnection("jdbc:mysql://ls-3696c8c5ea6858991e00efb9f56cd885b537c8e1.cygym1zxattm.ap-south-1.rds.amazonaws.com:3306/camagru", "username", "password");
  14. // our SQL SELECT query.
  15. // if you only need a few columns, specify them by name instead of using "*"
  16. String query = "SELECT * FROM users";
  17.  
  18. // create the java statement
  19. Statement st = conn.createStatement();
  20.  
  21. // execute the query, and get a java result set
  22. ResultSet rs = st.executeQuery(query);
  23.  
  24. String Username = rs.getString("username");
  25.  
  26. // print the results
  27. System.out.format("%sn", Username);
  28.  
  29. st.close();
  30. }
  31. catch (Exception e)
  32. {
  33. System.err.println("Got an exception! ");
  34. System.err.println(e.getMessage());
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement