Problems using MySQL
Posted by: Thomas Willms
Date: January 13, 2012 09:42AM

Hello,

I had some problems which trouble me. I solved them but I can't believe that the behavior I found is normal.

I use Java 1.6 and mysql 5.5 (from EasyPHP 5.3.7) running the system windows XP pro sp3.

first: Using the following code, having a jdbc - connection object open named con:

 public int test (String test){
       int id1 = -1; 
       String sql =""; 
       Statement s = null; 
       ResultSet rs =null;
        try {
         sql = "Select * from Country WHERE Country like '"+test + "'";
         s = con.createStatement();
         rs = s.executeQuery(sql);
             while (rs.next()) {  id1 = rs.getInt("id");       }
             rs.close(); s.close();
         } catch (SQLException ex) {System.out.println(ex+"a"); }

      return id1;
    }
I get one row as a result as it should be, but if I don't use while (rs.next() ) it doesn't work. I get an error because id stays on row -1 !!! The error appears if I step over rs.getInt("Id"). It does not appear with while (rs.next() ) { } but it appears without:
java.sql.SQLException: Before start of result set ID Deutschland = -1
I don't understand this. It happens with the innoDB and also with MyIsam.


Thanks for help

Thommy



Edited 7 time(s). Last edit at 01/15/2012 01:16PM by Thomas Willms.

Options: ReplyQuote


Subject
Written By
Posted
Problems using MySQL
January 13, 2012 09:42AM
January 13, 2012 12:21PM
January 13, 2012 01:26PM
January 13, 2012 02:40PM
January 15, 2012 01:30PM
January 15, 2012 05:21PM
January 16, 2012 02:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.