Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

error during reading data from Oracle database

843859Oct 29 2006 — edited Nov 2 2006
Hy.
I'am writting the application in java language that connects with Oracle database, creating simply table, inserts some data and takes them. The table has the columns of varchar type(ones is named question(varchar(400), because stores the very long objects of String, second is named answers(varchar(100)). I write the String's objects to table of database the below function:

protected void createTable(String nazTabeli) {
String createTable = null;
try{
createTable = "CREATE TABLE " + nazTabeli +
" (PYTANIE VARCHAR(32), ODPOWIEDZ VARCHAR(32))";
state.executeUpdate(createTable);
}catch(SQLException ex) {
System.out.println("\n--- SQLException caught ---\n");
try{
//deleting has already existed table
deleteTable(nazTabeli);

//creating a new table state.executeUpdate(createTable);
}catch(SQLException e){}
System.out.println("Message: " + ex.getMessage ()
}
}


protected void insertRecordTable(String pytanie, String odpowiedz,
String nazTabeli) {
String rekord = null;
try {
rekord = "INSERT INTO " + nazTabeli + " VALUES('" + pytanie +
"','" + odpowiedz + "')";
state.executeUpdate(rekord);
}catch(SQLException e) {}
}


Both of this function executing correctly but in java code I use the varchar type of columns of table, and when I check in Enterprise Console Mangater (tools of Oracle), the columns (question and answer) are the type varchar2.

Now the function trying to read data from database table:

protected String[] readAskAndAns(String nazTablicy) {
String tabPytIOdp[] = new String[2];
System.out.println("ilePytan: " + ilePytan);
try{
String query = "SELECT PYTANIE, ODPOWIEDZ FROM " +
nazTablicy;
ResultSet rs = state.executeQuery(query);
if (ilePytan > 0) {
tabPytIOdp[0] = rs.getString("PYTANIE"); // line 109
tabPytIOdp[1] = rs.getString("ODPOWIEDZ");
}
ilePytan--;
}catch(SQLException e) {e.printStackTrace();}
return tabPytIOdp;
}

when I starts this function (readAskAndAns()) then it's the error:

com.inet.ora.ab: [OraDriver] Not on a valid row.
at com.inet.ora.am.a(Unknown Source)
at com.inet.ora.am.a(Unknown Source)
at com.inet.ora.am.a(Unknown Source)
at com.inet.ora.k.d(Unknown Source)
at com.inet.ora.k.getBytes(Unknown Source)
at com.inet.ora.k.getString(Unknown Source)
at com.inet.ora.k.getString(Unknown Source)
at Baza.readAskAndAns(Baza.java:109).

I used j2sdk1.4.2_12, oracle 9i database, and the driver Seropto_Trial_2.12 version to connect to Oracle database.
I please for some help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2006
Added on Oct 29 2006
1 comment
280 views