android - 在android studio中使用JDBC,找不到合适的驱动程序
问题描述
我是这个 JDBC 驱动程序的新手。我正在寻找将用户数据从我的 android 应用程序保存到谷歌云 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 的方法。
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));
}
}
}
}
解决方案
推荐阅读
- django - 如何在 Django 1.11 中设置字符集标题
- sql-server - 如何正确使用 SET XACT_ABORT ON
- storybook - Storybook only loads stories when I make changes
- karate - 在空手道中,存储在两个变量中的值的比较如何大于或小于
- amazon-web-services - AWS CLI 仅列出授权存储桶
- node.js - 需要使用 TypeORM/NestJS 在 PostgreSQL 数据库中上传文件
- macos - 添加迁移命令在 Nuget 包管理器控制台中不起作用
- csv - Tcl如何修改csv,它可以在不使用tcllib的情况下控制另一个文件的数据
- amazon-web-services - AWS Codebuild:命令未成功退出
- javascript - 我已经使用这种 xmlhttprequest 方法来制作显示水质但无法正常工作的实时仪表图表?