Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to move cursor to next row?  RSS feed

ramesh kumar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!