Skip to content

Instantly share code, notes, and snippets.

@64lines
Last active August 5, 2016 04:58
Show Gist options
  • Select an option

  • Save 64lines/80b0083db7f837c796ab36699b58f78e to your computer and use it in GitHub Desktop.

Select an option

Save 64lines/80b0083db7f837c796ab36699b58f78e to your computer and use it in GitHub Desktop.
Java Database Connection to MySQL
String URL = "jdbc:mysql://localhost:5004/test";
try {
Connection conn = DriverManager.getConnection (URL, "username", "password");
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery("select * from tweet_post;");
while(resultSet.next()) {
System.out.println(resultSet.getString("id") + "\t" + resultSet.getString("tweet"));
}
} catch (SQLException ex) {
Logger.getLogger(Babylon.class.getName()).log(Level.SEVERE, null, ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment