Last active
August 29, 2015 14:18
-
-
Save dbadapt/879b0d565848b2f13009 to your computer and use it in GitHub Desktop.
MysqlVersion.java - Percona Live 2015 - Java 101 Talk Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
close ResultSet instance