File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes strange error while executing an insert statement in MS SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "strange error while executing an insert statement in MS SQL Server " Watch "strange error while executing an insert statement in MS SQL Server " New topic
Author

strange error while executing an insert statement in MS SQL Server

Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
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
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://aspose.com/file-tools
 
subject: strange error while executing an insert statement in MS SQL Server
 
Similar Threads
MS-SQL Data ResultSet Problem
Servlet and JDBC error
nested resultsets
how to fetch data from resultset containing result of two queries
RAD 7.5.0 - Data Perspective - This driver is locked for use with embedded applications