Created
October 24, 2016 13:51
-
-
Save mikhail-chystsiakou/796583832c6b2b4f9dc87e8ef6313eb6 to your computer and use it in GitHub Desktop.
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
/* | |
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(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//Usage:
StatementQuestion sq = new StatementQuestion();
sq.printData(5);
sq.printData(10);
sq.kill();