• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

moving cursor to the next row

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i would like to move the cursor to the next row and print the required values in the output. but it's showing driver doesnot support this property/ what could be the cause.i am using jdk1.3
here the code
//program to creat table, to enter values from the user
//the values are written into the created table
import java.sql.*;
import java.io.*;
class inserttable {
public static void main(String a[]) {

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection =DriverManager.getConnection("jdbc dbc:rajesh","sa","");
if(connection==null)
{ System.out.println("there is some error in connection"); }
Statement statement = connection.createStatement();
//String def = "create table MARKS " +
//"(NAME VARCHAR(32), " +
//"PHYSICS VARCHAR(32), "+
//"MATHS VARCHAR(32)) ";
//statement.executeUpdate(def);
String stri = "INSERT into MARKS (Name, Physics, Maths) values(?,?,?)";
PreparedStatement stmt = connection.prepareStatement(stri);
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.println("Enter student name");
String Name = br.readLine();
System.out.println("Enter physics marks");
String Physics = br.readLine();
System.out.println("Enter maths marks");
String Maths= br.readLine();
stmt.setString(1, Name);
stmt.setString(2,Physics);
stmt.setString(3,Maths);
stmt.executeUpdate();
ResultSet rs = stmt.executeQuery("select * from marks");
//here am getting problem, it's not givifng this output i require
while (rs.next() ){
System.out.println("name ==>"+rs.getString("Name")+"\n");
System.out.println("physics ==>"+rs.getString("Physics")+"\n");
System.out.println("Maths ==>"+rs.getString("Maths")+"\n");
rs.close();
}
statement.close();
connection.close();

}catch(ClassNotFoundException e)
{System.out.println("error");
}catch(SQLException ex)
{System.out.println("error" + ex.getMessage());
}catch(IOException ee){System.out.println("IO Error");}
}
}
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try setting the result set type to scrollable?
E.G.

 
paddy_1974
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Baiter:
[B]Did you try setting the result set type to scrollable?
E.G.
[/B]


the above statement does not work. pls help me.am using jdk1.3
am attaching my code below
//program to creat table, to enter values from the user
//the values are written into the created table
import java.sql.*;
import java.io.*;
import java.sql.ResultSet;
class inserttable {
public static void main(String a[]) {

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection =DriverManager.getConnection("jdbc dbc:rajesh","sa","");
if(connection==null)
{ System.out.println("there is some error in connection"); }
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
//String def = "create table MARKS " +
//"(NAME VARCHAR(32), " +
//"PHYSICS VARCHAR(32), "+
//"MATHS VARCHAR(32)) ";
//statement.executeUpdate(def);
String stri = "INSERT into MARKS (Name, Physics, Maths) values(?,?,?)";
PreparedStatement stmt = connection.prepareStatement(stri,ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.println("Enter student name");
String Name = br.readLine();
System.out.println("Enter physics marks");
String Physics = br.readLine();
System.out.println("Enter maths marks");
String Maths= br.readLine();
stmt.setString(1, Name);
stmt.setString(2,Physics);
stmt.setString(3,Maths);
stmt.executeUpdate();
ResultSet rs = stmt.executeQuery("select * from marks");
rs.beforeFirst();
//Vector my=new Vector();
while (rs.next()){
System.out.println("name ==>"+rs.getString("Name")+"\n");
System.out.println("physics ==>"+rs.getString("Physics")+"\n");
System.out.println("Maths ==>"+rs.getString("Maths")+"\n");
//System.out.println(my.getString("Name")+"\n");
//rs.close();
}
statement.close();
connection.close();

}catch(ClassNotFoundException e)
{System.out.println("error");
}catch(SQLException ex)
{System.out.println("error" + ex.getMessage());
}catch(IOException ee){System.out.println("IO Error");}
}
}
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
paddy_1974,
Your name is not JavaRanch compliant. You'll get in trouble with a sheriff. Change it before you get caught and get put in jail! I don't think you get to pass go and collect $200 either.
Please read the FAQ to learn how to format your code so it's more readable. If you do that, I promise to take a crack at your problem.
-Peter
 
paddy_1974
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi here is my code: psl help
//program to creat table, to enter values from the user
//the values are written into the created table
// the error is driver does not support this property after accepting input values namely name,physics,maths etc.


[This message has been edited by Thomas Paul (edited January 09, 2001).]
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ugh...Your code is still not formatted correctly. Please read the FAQ link to learn how-to format your code correctly.
If you were me, would you want to read code formatted like this?
-Peter
[This message has been edited by Peter Tran (edited January 09, 2001).]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this line may be causing the problem:
ResultSet rs = stmt.executeQuery("select * from marks");
stmt is actually a PreparedStatement object. Although PreparedStatement is a child of Statement and therefore supports the executeQuery(String) method, I have no idea how it is actually implemented. It may be that the PreparedStatement class in the JdbcOdbc set doesn't correctly support this. Try running the query off a new Statement object. And get rid of the "ResultSet.TYPE_SCROLL_SENSITIVE" commands. Those are part of JDBC 2 and may not be supported by the driver you are using. In any case, they are not needed.
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic