Skip to content

Instantly share code, notes, and snippets.

@dbadapt
Last active August 29, 2015 14:18
Show Gist options
  • Save dbadapt/879b0d565848b2f13009 to your computer and use it in GitHub Desktop.
Save dbadapt/879b0d565848b2f13009 to your computer and use it in GitHub Desktop.
MysqlVersion.java - Percona Live 2015 - Java 101 Talk Example
// Simple Java JDBC example
// Edit db.properties for your environment
// Compile: javac DBHello.java
// Run: java -cp .:{jdbc.jar} DBHello
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
public class DBHello {
public static void main(String[] args)
throws SQLException,ClassNotFoundException,IOException {
Properties dbp = new Properties();
dbp.load(DBHello.class.getClassLoader()
.getResourceAsStream("db.properties"));
Class.forName(dbp.getProperty("class"));
Connection con =
DriverManager.getConnection(dbp.getProperty("url"), dbp);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(dbp.getProperty("versionQuery"));
if (rs.next()) {
System.out.printf("Hello from %s\n",rs.getString("version"));
}
rs.close(); st.close(); con.close();
}
}
@dbadapt
Copy link
Author

dbadapt commented Apr 11, 2015

close ResultSet instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment