Skip to content

Instantly share code, notes, and snippets.

Created April 16, 2013 13:26
Show Gist options
  • Save anonymous/5395863 to your computer and use it in GitHub Desktop.
Save anonymous/5395863 to your computer and use it in GitHub Desktop.
H2 example
public class h2_example {
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
public static void main(String... args){
Connection connection = null;
ResultSet resultSet = null;
Statement statement = null;
try {
// Class.forName("org.h2.Driver");
connection = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT EMPNAME FROM employeedetails");
while (resultSet.next()) {
System.out.println("EMPLOYEE NAME:"
+ resultSet.getString("EMPNAME"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
resultSet.close();
statement.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment