I would like move to next or prev records in a Resultset, clicking other listeners bottons.
What the best way to do it ?
Thanks.
There is my code :
class Listener1 implements ActionListener {
public void actionPerformed(ActionEvent ev) {
String url= "jdbc:mysql://127.0.0.1/mydb";
Connection con;
String query = "SELECT * FROM demo WHERE (" + search1 + " LIKE '%" + value1 + "%' AND " + search2 + " LIKE '%" + value2 + "%' AND " + search3 + " LIKE '%" + value3 + "%')";
Statement stmt;
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
System.out.println("Trying to connect...");
con = DriverManager.getConnection (url,"apffal", "");
System.out.println("connected!");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet result = stmt.executeQuery(query);
result.afterLast();
while (result.previous()) {
String rel = result.getString(1);
String proc = result.getString(2);
String data = result.getString(3);
trl8.t1.setText(rel);
trl8.t2.setText(proc);
trl8.t3.setText(data);
}
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.print("SQLException: ");
System.err.println(ex.getMessage());
}
}
}
What the best way to do it ?
Thanks.
There is my code :
class Listener1 implements ActionListener {
public void actionPerformed(ActionEvent ev) {
String url= "jdbc:mysql://127.0.0.1/mydb";
Connection con;
String query = "SELECT * FROM demo WHERE (" + search1 + " LIKE '%" + value1 + "%' AND " + search2 + " LIKE '%" + value2 + "%' AND " + search3 + " LIKE '%" + value3 + "%')";
Statement stmt;
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
System.out.println("Trying to connect...");
con = DriverManager.getConnection (url,"apffal", "");
System.out.println("connected!");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet result = stmt.executeQuery(query);
result.afterLast();
while (result.previous()) {
String rel = result.getString(1);
String proc = result.getString(2);
String data = result.getString(3);
trl8.t1.setText(rel);
trl8.t2.setText(proc);
trl8.t3.setText(data);
}
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.print("SQLException: ");
System.err.println(ex.getMessage());
}
}
}