在android studio中使用jdbc,找不到合适的驱动程序

plupiseo  于 2021-06-15  发布在  Mysql
关注(0)|答案(0)|浏览(267)

我是这个jdbc驱动程序的新手。我正在寻找将android应用程序中的用户数据保存到google云mysql的方法。我碰巧遇到jdbc可能会完成这个任务。
但是,我遇到了这个错误 No suitable driver found for jdbc:mysql://google/waveUserData?cloudSqlInstance=wavdata&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false 我已经下载了jdbc驱动程序并将其放入 /library/java/extensions 请帮助我这个,或者请给我推荐一个方法,有效地从应用程序到谷歌云mysql的用户数据。
这是我指的代码:https://github.com/googlecloudplatform/cloud-sql-jdbc-socket-factory/blob/master/examples/compute-engine/src/main/java/com/google/cloud/sql/mysql/example/listtables.java

package com.google.cloud.sql.mysql.example;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**

* A sample app that connects to a Cloud SQL instance and lists all       available tables in a database.
* /

public class ListTables {
  public static void main(String[] args) throws IOException,   SQLException {
    // TODO: fill this in
   // The instance connection name can be obtained from the instance overview page in Cloud Console
// or by running "gcloud sql instances describe <instance> | grep connectionName".
String instanceConnectionName = "<insert_connection_name>";

// TODO: fill this in
// The database from which to list tables.
String databaseName = "mysql";

String username = "root";

// TODO: fill this in
// This is the password that was set via the Cloud Console or empty if never set
// (not recommended).
String password = "<insert_password>";

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);
}

//[START doc-example]
String jdbcUrl = String.format(
    "jdbc:mysql://google/%s?cloudSqlInstance=%s"
        + "&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false",
    databaseName,
    instanceConnectionName);

Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
   //[END doc-example]

try (Statement statement = connection.createStatement()) {
  ResultSet resultSet = statement.executeQuery("SHOW TABLES");
  while (resultSet.next()) {
    System.out.println(resultSet.getString(1));
      }
    }
  }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题