Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange error while executing an insert statement in MS SQL Server

 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic