Skip to content

Instantly share code, notes, and snippets.

@mikhail-chystsiakou
Created October 24, 2016 13:51
Show Gist options
  • Save mikhail-chystsiakou/796583832c6b2b4f9dc87e8ef6313eb6 to your computer and use it in GitHub Desktop.
Save mikhail-chystsiakou/796583832c6b2b4f9dc87e8ef6313eb6 to your computer and use it in GitHub Desktop.
/*
required imports
*/
puclic class StatementQuestion {
Connection cn;
PreparedStatement ps;
public StatementQuestion() throws ClassNotFoundException, SQLException{
cn = DriverManager.getConnection("path", "user", "pass");
ps = cn.prepareStatement("select `data` from table where id > ?");
}
public void printData(int id) throws SQLException {
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
while(rs.next()) {
System.out.prinlnt(rs.getInt("data"));
}
rs.close();
}
public void kill() throws SQLException{
ps.close();
cn.close();
}
}
@mikhail-chystsiakou
Copy link
Author

//Usage:
StatementQuestion sq = new StatementQuestion();
sq.printData(5);
sq.printData(10);
sq.kill();

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