This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
hello, I had one problem jdbc.I am using Ms Acess database.If i use rs.next() it gives no problem.Here rs stands for Resultset. while usins rs.previous() it gives me a error saying java.lang.unsupportedoperationException.
I have created table with two columns ,I am using awt as fronthand in that i created two textfield for dispaly of two columns from the table,and two Button one button by name Next and another button by name Previous.If i press Next button it will retrive frist row from the table and will be displayed in the textfield.Once again if i press Next button it display the next row from the table.Here In the Next Button there is no problem.I have problem in the previous Button.I could'nt able to move Backwords in the table. If i use rs.previous() i gives me a error as i mention before. Please help me in this with coding.Along with this i am attaching My program so please make some changes so that i is possible to move to the previous row. Program is given below import java.awt.*; import java.awt.event.*; import java.sql.*; class But1 extends Frame implements ActionListener { int i=1; Button next; Button pre; TextField t1; TextField t2; Connection co; Statement st; ResultSet rs; But1() { super("My Button"); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Driver registered "); co=DriverManager.getConnection("jdbc dbc:vicky"); System.out.println("Connection Established"); setSize(300,300); setLayout(new FlowLayout()); next=new Button("Next"); pre =new Button("Prev"); t1=new TextField(10); t2=new TextField(10); add(t1); add(t2); add(next); add(pre); next.addActionListener(this); pre.addActionListener(this); setVisible(true); } catch(ClassNotFoundException ce) { System.out.println(ce); } catch(Exception e) { System.out.println(e); } } public void actionPerformed(ActionEvent ae) { if(ae.getActionCommand()=="Next") { try { st=co.createStatement(); rs=st.executeQuery("Select * from mytable "); while(rs.next()) { if(rs.getInt(1)==i) { t1.setText(rs.getString(2)); t2.setText(rs.getString(3)); }
} } class But { public static void main(String a[]) { But1 b=new But1(); } }
Please help me in coding.
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
The exception says it all, really: your JDBC driver does not support the previous() method. If you want to go to the previous record you'll either have to cache your result set or redo the query. Or something in between -- cache a certain number of results, re-querying when you need a record not in your cache. - Peter
[This message has been edited by Peter den Haan (edited March 03, 2001).]
Rajesh Kumar77
Greenhorn
Joined: Sep 04, 2001
Posts: 12
posted
0
to use rs.previous() method you need to have jdk 1.3 in your system pl check the following code in your system after giving jdbc connections import java.sql.*; public class MyConnection { Connection con; MyConnection() { try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc dbc:dsnaccess","",""); } catch(Exception e) { System.out.println(" in myconnection.java file " +e); } } }
if(ae.getSource()==reset) { userPanel.removeAll(); userIDTxt.setText(""); userNameTxt.setText(""); } if(ae.getSource()==exit) { System.exit(0); } } public static void main(String args[]) { new UserSearchMod(); } } ******+ just try this program and give me feed back i am facing the pblm with sql server in the same situation even if i use jdk 1.3 help me bye
the driver you are using does not support the rs.previous(), as well as many other methods. That means that you CAN NOT use them. If you want to use them, you will have to get a new jdbc 2.0 COMPLIANT driver. Otherwise, you will have to deal with not using rs.previous() and other such methods. Jamie