aspose file tools*
The moose likes JDBC and the fly likes why is this happening URGENT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "why is this happening URGENT" Watch "why is this happening URGENT" New topic
Author

why is this happening URGENT

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
Im attempting to query info. Using MS SQL 7.0. Using statement SELECT * FROM Table1 WHERE Invoice = '" + string + "'" .
This is to return a row with about 32 columns. I can read the read info from the first column and then I have no idea what happens.. I have a swith statement which determines the column TYPE eg: case TYPE.VARCHAR
return rsv.getString(x);
the code enters the case and then an Invalid Cursor State is thrown. The info is present in the SQL. Im really confused.
Im stuck here can someone please help.
Thank u
------------------
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
Could it be that you are trying to access the columns out of sequence?
when you do select *... i suppose one has to retrieve the columns in the same order as they are in the table.
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
no im taking them in order
------------------
Yogen Vadnere
Ranch Hand

Joined: Sep 20, 2001
Posts: 58
would u mind to post ur code ? so that we can fig out whats wrong with it.

Yogen Vadnere
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
Hope someone can help
private void display(ResultSet rs)
{
try
{
rsmd = rs.getMetaData();
rs.next();
String plant = rs.getString(3);
if( plant != null)
{
items[0] = plant;
int y = 1;
for(int x = 4 ; x < 38; x++)
{
rs.next();
items[y] = getNextRowShow(rs, rsmd, x);
y++;
}
}
}
catch(SQLException sqlex)
{
sqlex.printStackTrace();
}
}
private String getNextRowShow(ResultSet rsv, ResultSetMetaData rsmd, int y)
{
try
{
//returns the Type of Column
//each type is represented by a
//integer value
int x = rsmd.getColumnType(y);
switch (x)
{
case Types.DECIMAL://used for number fields
return new Float(rsv.getFloat(y)).toString();//getFloat() returns a float
case Types.VARCHAR:
return rsv.getString(y);//getString returns a String
case Types.INTEGER:
return new Long(rsv.getLong(y)).toString();
case Types.TIMESTAMP:
return rsv.getTimestamp(y).toString();
default:
}
}
catch(SQLException sqle)
{
sqle.printStackTrace();
}
return null;
}

------------------
Yogen Vadnere
Ranch Hand

Joined: Sep 20, 2001
Posts: 58
i modified the code...
try following code.....
let me know if u have problem

private void display(ResultSet rs)
{
try
{
rsmd = rs.getMetaData();
rs.next();
String plant = rs.getString(3);
if( plant != null)
{
items[0] = plant;
int y = 1;
for(int x = 4 ; x < 38; x++)
{
///////////////////////////
if(rs != null && rs.next()){
items[y] = getNextRowShow(rs, rsmd, x);
y++;
}else{
break ;
}
//////////////////////
}
}
}
catch(SQLException sqlex)
{
sqlex.printStackTrace();
}
}
private String getNextRowShow(ResultSet rsv, ResultSetMetaData rsmd, int y)
{
try
{
//returns the Type of Column
//each type is represented by a
//integer value
int x = rsmd.getColumnType(y);
switch (x)
{
case Types.DECIMAL://used for number fields
return new Float(rsv.getFloat(y)).toString();//getFloat() returns a float
case Types.VARCHAR:
return rsv.getString(y);//getString returns a String
case Types.INTEGER:
return new Long(rsv.getLong(y)).toString();
case Types.TIMESTAMP:
return rsv.getTimestamp(y).toString();
default:
}
}
catch(SQLException sqle)
{
sqle.printStackTrace();
}
return null;
}
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331

Thank u for your time
but it still does not work when it comes to this part of the
code it goes directly into the else part. rs isnt null and
it happpens when it tries to read rs. next.
if(rs != null && rs.next()){
items[y] = getNextRowShow(rs, rsmd, x);
y++;
}else{
break ;
}
I even tried
rs.next();
String s = rs.getString(1);
rs.next();
String s = rs.getString(2);
rs.next();
String s = rs.getString(3);
it would read the first item and when I tried to
read the second it would throw the exception
invalid cursor state


------------------
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87



i am confused.
i assume that the for loop is to get values of columns 4 to 37 for the current row.
inside the loop, why do you then move to the next row by using 'rs.next()'??
Yogen Vadnere
Ranch Hand

Joined: Sep 20, 2001
Posts: 58
shilpa is right..
just remove the rs.next() stmt from the for loop and then test...
and for the first rs.next() use if(rs.next(){}else{}
hope this will help...
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
thank u all for your time . Sometimes the mistake
is so obvious yet i cant see it.
Thanks again
------------------
 
jQuery in Action, 2nd edition
 
subject: why is this happening URGENT