Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ListTables {
- public static void main(String[] args) throws IOException, SQLException {
- String instanceConnectionName = "<foo:foo:bar>";
- String databaseName = "myDatabaseName ";
- String username = "myUsername ";
- String password = "<myPass>";
- if (instanceConnectionName.equals("<insert_connection_name>")) {
- System.err.println("Please update the sample to specify the instance connection name.");
- System.exit(1);
- }
- if (password.equals("<insert_password>")) {
- System.err.println("Please update the sample to specify the mysql password.");
- System.exit(1);
- }
- String jdbcUrl = String.format(
- "jdbc:mysql://google/%s?cloudSqlInstance=%s&"
- + "socketFactory=com.google.cloud.sql.mysql.SocketFactory",
- databaseName,
- instanceConnectionName);
- try{
- Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
- /* try (Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery("select * from wf_accounts;");
- while (resultSet.next()) {
- System.out.println(resultSet.getString(1));
- }
- }*/
- }catch(Exception ex){
- System.out.println("Error: " + ex.toString());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement