This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: strange error while executing an insert statement in MS SQL Server
 
It's not a secret anymore!