我有一个用Java / Swing mysql构建的软件。我可以使用任何Cloud Service来存储和检索JDBC数据吗?或者我还能用什么?
答案 0 :(得分:1)
是的,有几个SQL-in-the-cloud选项,包括提供MySQL的 Amazon RDS 和 Google Cloud SQL 。设置完成后,您可以像使用任何其他MySQL数据库一样使用JDBC连接它们。
答案 1 :(得分:0)
请检查以下代码以获取参考号
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.google.appengine.api.utils.SystemProperty" %>
<html>
<body>
<%
String url = null;
if (SystemProperty.environment.value() ==
SystemProperty.Environment.Value.Production) {
// Load the class that provides the new "jdbc:google:mysql://" prefix.
Class.forName("com.mysql.jdbc.GoogleDriver");
url = "jdbc:google:mysql://your-project-id:your-instance-name/guestbook?user=root";
} else {
// Local MySQL instance to use during development.
Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://127.0.0.1:3306/guestbook?user=root";
}
Connection conn = DriverManager.getConnection(url);
ResultSet rs = conn.createStatement().executeQuery(
"SELECT guestName, content, entryID FROM entries");
%>
<table style="border: 1px solid black">
<tbody>
<tr>
<th width="35%" style="background-color: #CCFFCC; margin: 5px">Name</th>
<th style="background-color: #CCFFCC; margin: 5px">Message</th>
<th style="background-color: #CCFFCC; margin: 5px">ID</th>
</tr>
<%
while (rs.next()) {
String guestName = rs.getString("guestName");
String content = rs.getString("content");
int id = rs.getInt("entryID");
%>
<tr>
<td><%= guestName %></td>
<td><%= content %></td>
<td><%= id %></td>
</tr>
<%
}
conn.close();
%>
</tbody>
</table>
</body>
</html>