strange error while executing an insert statement in MS SQL Server
Subbu Aswathanarayan
Ranch Hand
Joined: Jun 22, 2001
Posts: 73
posted
0
Hi all, i am using MS SQL Server and JDBC-ODBC bridge.i am having a very strange problem while trying to execute an insert statement. i get an saying database is busy with the results of another hstmt. by trial and error i found out that this was because of a SELECT statement a couple of lines above the INSERT statement.i was getting the result of the SELECT statement in a resultset.so i thought, probably the resultset was engaging the connection and explicitly closed it using rs.close().but even that doesn't help. when i removed the rs = select ...... statement, everything seems to be working fine.but i need that select statement.its a must. please help me out. thanks in advance. Subbu
Subbu
Dorj Galaa
Ranch Hand
Joined: May 29, 2001
Posts: 113
posted
0
SELECT import java.sql.*; public class ConnectToMSSQL { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection ("jdbc dbc:yuorodbcdsn","username","password"); String Query="select * from users order by contractno"; Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet Result=st.executeQuery(Query); while (Result.next()) { System.out.println(Result.getString(2)); } Result.close(); st.close(); conn.close(); } catch(ClassNotFoundException e) { System.out.println(e.getMessage()); } catch(SQLException e) { System.out.println(e.getMessage()); } } } it's working correctly to update data try Query=update .... if (st.executeupdate(Query)!=) { code }
Senior software engineer
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: strange error while executing an insert statement in MS SQL Server