Skip to content

Instantly share code, notes, and snippets.

@tedheich
Created November 25, 2009 13:19
Show Gist options
  • Save tedheich/242696 to your computer and use it in GitHub Desktop.
Save tedheich/242696 to your computer and use it in GitHub Desktop.
Boiler plate code in java database programming - using sqlite
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
class DBSample {
public static void main(String []args){
Connection cn = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("org.sqlite.JDBC");
cn = DriverManager.getConnection("jdbc:sqlite:sample.db");
st = cn.createStatement();
rs = st.executeQuery("SELECT * FROM user;");
while(rs.next()) {
System.out.print(rs.getString(1));
System.out.print(rs.getString(2));
System.out.println(rs.getString(3));
}
}
catch(ClassNotFoundException ce) {
ce.printStackTrace();
}
catch(SQLException sqle) {
sqle.printStackTrace();
}
finally {
try {
rs.close();
st.close();
cn.close();
}
catch(SQLException sqle) {
sqle.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment