Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I am going *#&^! NUT about JDBC

1 view
Skip to first unread message

asy...@search.org

unread,
Jan 4, 1999, 3:00:00 AM1/4/99
to

Yo,

Has anyone successfully executed a prepared statement multiple times
without re-creating it with SUN's JDBC-ODBC bridge and MS SQL Server
6.5? Specifically, something like the following:


PreparedStatement pstmt;
pstmt = con1.prepareStatement("select * from authors\n");

for(int t = 0; t < 5; t++)
{
System.out.println("t: " + t);
rs = pstmt.executeQuery();
while(rs.next())
{
System.out.println(rs.getString(1) + " " + rs.getString(2));
}
rs.close();
}

I am using Windows NT 4.0, JDK 1.2beta4, and MS SQL Server 6.5 and I
keep getting this. I am looping through the crap 5 times, but I fail
on the 2nd round, why, why oh my why????

t: 0
172-32-1176 White
213-46-8915 Green
238-95-7766 Carson
267-41-2394 O'Leary
274-80-9391 Straight
341-22-1782 Smith
409-56-7008 Bennet
427-17-2319 Dull
472-27-2349 Gringlesby
486-29-1786 Locksley
527-72-3246 Greene
648-92-1872 Blotchet-Halls
672-71-3249 Yokomoto
712-45-1867 del Castillo
722-51-5454 DeFrance
724-08-9931 Stringer
724-80-9391 MacFeather
756-30-7391 Karsen
807-91-6654 Panteley
846-92-7186 Hunter
893-72-1158 McBadden
899-46-2035 Ringer
998-72-3567 Ringer
t: 1
java.sql.SQLException: Invalid state for getResultSet
at
sun.jdbc.odbc.JdbcOdbcStatement.getResultSet(JdbcOdbcStatement.java:2
53)
at
sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(JdbcOdbcPrepared
Statement.java:106)
at JdbcOdbc.main(JdbcOdbc.java:49)


Please note 't: '...a million kudos to whoever that can help me...:-)

Chris Sellars

unread,
Jan 4, 1999, 3:00:00 AM1/4/99
to
Do not use PreparedStatement...just Statement and you should be fine.

Statement stmt = conn.createStatement();
rs = stmt.executeQuery("select * from authors");

Good Luck...

Tri H. Nguyen

unread,
Jan 4, 1999, 3:00:00 AM1/4/99
to
I guess the problem is rs.close() in the for loop. If rs.close() is called
after the while loop, you might
have to initialize it again at the begining of the for loop. Otherwise, rs
is "dangling".

PS: If it does not solve your problem, please do not yell at me. I'm still
learning JDBC.

Good luck.

- Tri

asy...@search.org wrote in message <3690721d.1828228@news-server>...

Dirk Bosmans

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
I'm reacting to following parts of asy...@search.org's article in comp.lang.java.databases on Mon, 04 Jan 1999 07:50:55
GMT6

>
>Yo,
>
>Has anyone successfully executed a prepared statement multiple times
>without re-creating it with SUN's JDBC-ODBC bridge and MS SQL Server
>6.5? Specifically, something like the following:
>
>
> PreparedStatement pstmt;
> pstmt = con1.prepareStatement("select * from authors\n");
>
> for(int t = 0; t < 5; t++)
> {
> System.out.println("t: " + t);
> rs = pstmt.executeQuery();
> while(rs.next())
> {
> System.out.println(rs.getString(1) + " " + rs.getString(2));
> }
> rs.close();
> }

Stop guessing what happens. First try/catch the SQLException, and print out SQLState, SQLCode and Message for each next
SQLException in the chain.


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
^ _/_/_/_/ _/_/ _/_/_/_/ _/ _/ v
^ _/ _/ _/_/ _/ _/ _/ _/ v
^ _/ _/ _/_/ _/_/_/_/ _/_/_/ v
^ _/ _/ _/_/ _/ _/ _/ _/ v
^ _/_/_/_/ _/_/ _/ _/ _/ _/ v
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Dirk de Pirk

Mark Thornton

unread,
Jan 6, 1999, 3:00:00 AM1/6/99
to
In article <3692c738...@news.ping.be>, Dirk.B...@ping.be (Dirk
Bosmans) wrote:

>
> Stop guessing what happens. First try/catch the SQLException, and print
> out SQLState, SQLCode and Message for each next
> SQLException in the chain.
>
>
>

Actually you are the one who should stop guessing. This doesn't work
reliably because there are bugs in the JDBC driver. In this case you don't
get sensible exceptions (often the JVM just crashes).

Mark Thornton

0 new messages