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...:-)
Statement stmt = conn.createStatement();
rs = stmt.executeQuery("select * from authors");
Good Luck...
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>...
>
>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
>
> 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