Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public class ListTables {
  2. public static void main(String[] args) throws IOException, SQLException {
  3.  
  4. String instanceConnectionName = "<foo:foo:bar>";
  5.  
  6. String databaseName = "myDatabaseName ";
  7.  
  8. String username = "myUsername ";
  9.  
  10. String password = "<myPass>";
  11.  
  12. if (instanceConnectionName.equals("<insert_connection_name>")) {
  13. System.err.println("Please update the sample to specify the instance connection name.");
  14. System.exit(1);
  15. }
  16.  
  17. if (password.equals("<insert_password>")) {
  18. System.err.println("Please update the sample to specify the mysql password.");
  19. System.exit(1);
  20. }
  21.  
  22. String jdbcUrl = String.format(
  23. "jdbc:mysql://google/%s?cloudSqlInstance=%s&"
  24. + "socketFactory=com.google.cloud.sql.mysql.SocketFactory",
  25. databaseName,
  26. instanceConnectionName);
  27. try{
  28. Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
  29.  
  30. /* try (Statement statement = connection.createStatement()) {
  31. ResultSet resultSet = statement.executeQuery("select * from wf_accounts;");
  32. while (resultSet.next()) {
  33. System.out.println(resultSet.getString(1));
  34. }
  35. }*/
  36.  
  37.  
  38. }catch(Exception ex){
  39. System.out.println("Error: " + ex.toString());
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement