Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onClick(View v) {
- // create our mysql database connection
- try {
- System.out.println("Loading driver...");
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Driver loaded!");
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Cannot find the driver in the classpath!", e);
- }
- try
- {
- Connection conn;
- conn = DriverManager.getConnection("jdbc:mysql://ls-3696c8c5ea6858991e00efb9f56cd885b537c8e1.cygym1zxattm.ap-south-1.rds.amazonaws.com:3306/camagru", "username", "password");
- // our SQL SELECT query.
- // if you only need a few columns, specify them by name instead of using "*"
- String query = "SELECT * FROM users";
- // create the java statement
- Statement st = conn.createStatement();
- // execute the query, and get a java result set
- ResultSet rs = st.executeQuery(query);
- String Username = rs.getString("username");
- // print the results
- System.out.format("%sn", Username);
- st.close();
- }
- catch (Exception e)
- {
- System.err.println("Got an exception! ");
- System.err.println(e.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement