Reputation: 2696
I Have a software built in Java/Swing mysql. Can I use any Cloud Service for storing and retrieving data with JDBC? or what else i can use?
Upvotes: 1
Views: 3219
Reputation: 137
Check following code for ref.
<%@ 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>
Upvotes: 0
Reputation: 2867
Yes, there are several SQL-in-the-cloud options, including Amazon RDS and Google Cloud SQL both of which offer MySQL. Once set up, you can connect to them using JDBC like any other MySQL database.
Upvotes: 1