从 Java 独立应用程序连接到 Google Cloud sql [英] Connecting to Google cloud sql from Java stand alone application
问题描述
我想编写一个java独立应用程序来连接到google cloud sql
- MySql
数据库.我可以找到应用程序客户端的示例,但不能找到独立的 Java 应用程序.
I want to write a java stand alone application to connect to google cloud sql
- MySql
database. I could find samples for app client but not for a stand alone java application.
当我尝试执行此操作时,出现以下错误.
When I tried to do this, I get the following error.
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:google:mysql://IP:Instance_name?user=user_name");
Statement st = con.createStatement();
ResultSet rs = con.createStatement().executeQuery("SELECT 1 + 1");
失败并报错:
没有找到适合 jdbc:google:mysql:...
我看到一些他们要求启用 mysql 连接器的答案.但应用引擎项目就是这种情况.我如何使用独立应用程序来做到这一点?
I see some answers where they have asked to enabled mysql connector. But it is the case with app engine project. How do I do it with stand alone application?
推荐答案
你可以使用标准的mysql
连接器连接到云sql
实例:例如:>
You can just use the standard mysql
connector to connect to cloud sql
instance: e.g:
DriverManager.getConnection("jdbc:mysql://IP:Instance_name?user=user_name");
您可以查看此链接 https://cloud.google.com/sql/docs/外部了解更多信息.
You can check this link https://cloud.google.com/sql/docs/external for more information.
这篇关于从 Java 独立应用程序连接到 Google Cloud sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!