File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes How to move cursor to next row? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to move cursor to next row?" Watch "How to move cursor to next row?" New topic

How to move cursor to next row?

ramesh kumar
Ranch Hand

Joined: Nov 16, 2000
Posts: 32
Hi friends,
I am doing a assignment which creats a database, then takes
the database values during program execution, also known as
dynamic allocation. my problem is how to move the cursor or control after it reads the first row of values?
my working code is below. this pgm saves one row of data. HOw to save multiple rows? I've tried using loops. but still I think
I miss something. Pls help me.
thanks friends.

//program to creat table, to enter values from the user
//the values are written into the created table
import java.sql.*;
class MarksTable {
public static void main(String a[]) {

Connection connection =DriverManager.getConnection("jdbcdbc:ramesh","","");
{ System.out.println("there is some error in connection"); }
Statement statement = connection.createStatement();
String def = "create table MARKS " +
"(NAME VARCHAR(32), " +
InputStreamReader ir = new InputStreamReader(;
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();
String stri = "INSERT into MARKS (Name, Physics, Maths)" + "values(?,?,?)";
PreparedStatement stmt = connection.prepareStatement(stri);
stmt.setString(1, Name);
int row = stmt.executeUpdate();


}catch(ClassNotFoundException e){System.out.println("error");
}catch(SQLException ex) {System.out.println("errrorrrrrrr" + ex.getMessage());
}catch(IOException ee){System.out.println("IO Error");}
[This message has been edited by Thomas Paul (edited December 14, 2000).]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You don't need to do anything with a cursor. You need to put your logic that reads from the screen and runs the PreparedStatement in a loop. You will also need some for the person entering the information to tell you when the last entry has been made (something like "end" in the name field, for example).

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
This situation is a very good cadidate for prepared (pre-compiled) statements. Just have ? ? ? in the places where your want to change the inputs and execute the SAME pre-compiled statement again which is FASTER.
maha anna
I agree. Here's the link:
subject: How to move cursor to next row?
It's not a secret anymore!