.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

JDBC PreparedStatement insert fails with no exception

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :Sql Server
We are calling executeUpdate() on a PreparedStatement to do an insert.
The call does not throw an exception but the value returned is -1 which indicates that no rows were inserted.

We were using JDBC 2.0, but upgrading to 3.0 made no difference.

The instance in question is a Developer Edition with this version:

Microsoft SQL Server 2008 (SP1) - 10.0.2757.0 (X64)   Jan  8 2010 19:55:08  
Developer Edition (64-bit) on Windows NT 6.0 <X64> (Build 6002: Service Pack 2)

Using a different instance works as expected. Its version is:

Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64)   Mar 29 2009 10:11:52  
Developer Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: )

Executing an insert from SSMS into the table in the problem instance works just fine.

JVM version is

java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode)

View Complete Post

More Related Resource Links

SQL Null Insert fails

I am developing an SSIS package and trying to update an existing table with info from new columns.  In other words, this table already has records for my input CSV file.  But this CSV file has additional columns for these same records.  So I need to keep existing columns in table.  How can I achieve this? I began by using Import/Export Wizard and it did most of hard work for me.  But one of the columns previously defined in this table doesn't allow NULLs.  So although I want these new rows to map into existing table, it seems like this will just overwrite the table values and I get the error below.  How can I fix this? I have a Flat File CSV source, Data Conversoin, and DestinationConnectionOLEDB Error: 0xC0202009 at Data Flow Task 1, Destination - j5c_ALL_DATA2 [138]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "The statement has been terminated.". An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80004005 Description: "Cannot insert the value NULL into column 'timestamp', table 'berkeley.dbo.j5c_ALL_DATA2'; column does not allow nulls. INSERT fails.". Error: 0xC0209029 at Data Flow Task 1, Destinati

SSRS 2008 Export to PDF fails for large data with System.Exception: Parameter is not valid

Hi, We are working on Range Bar Chart using SSRS 2008. The report has huge data. It is properly displaying the data, but when we tried to export to pdf it is failing with the following exception. Exporting to excel works fine. Also if the report has small/medium data it is property exporting to PDF. It is failing only in case of huge data (we have custom page size of 28" X 14"). Of course the report has lot of expressions we used to customize the colors/text as per our requirements.   Server Error in '/Reports_SQLDEV2008' Application. Parameter is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Exception: Parameter is not valid. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:   [Exception: Parameter is not valid.]   [Exception: An error occurred during rendering of the report.]   [Exception: An error occurred during rendering of the report.]    Microsoft.Reporting.WebForms.ServerReport.ServerUrlRequest(Boolean isAbortable, String url, Stream ou

SSIS package fails giving "System.Runtime.InteropServices.COMException" exception


I am trying to execute the package in SQL Server 2008 and i am getting this error.


Executed as user: sql\SYSTEM. Microsoft (R) SQL Server Execute Package Utility  Version 10.0.2531.0 for 32-bit  Copyright (C) Microsoft Corp 1984-2005. All rights reserved.    

Started:  11:07:09 AM  Error: 2010-09-20 11:07:10.95     Code: 0x00000000     Source: Transform Data Task  undefined      

Description: System.Runtime.InteropServices.COMException (0x80040428): Package failed because Step 'DTSStep_DTSDataPumpTask_1' failed.     at DTS.PackageClass.Execute()     at Microsoft.SqlServer.Dts.Tasks.Exec80PackageTask.Exec80PackageTask.ExecuteThread()  End Error  DTExec: 

The package execution returned DTSER_FAILURE (1).  Started:  11:07:09 AM  Finished: 11:07:10 AM  Elapsed:  1.094 seconds.  The package execution failed.  The step failed.


Do any one have a clue


MOSS 2007 to SharePoint 2010 Upgrade Fails - Exception: The user or group 'wsaarole:wsaa administra


Ok the top part of the error I have tracked down to some entries in the SharePoint_Config database (Classes, Objects, TimerRunningJobs) and since I have a VM I am going to study them and try deleting them probably, if it dies I will delete this VM and roll up another VM in my case its a timer job that I am guessing the farm can live without.

The other error further down is more of a concern to me which is the one I listed above. The Group exists and it is in the farm and appears to be healthy no errors in preugrade check or the like or in the Farm. When upgrading the show stopper for me is that the content databases will not upgrade (assuming they upgrade FBA I can configure) the chicken and egg issue for me is this is an FBA farm, so is it the case that b/c FBA is missing not configured yet on the other side of the upgrade in 2010 that these content dbs connected to FBA (by FBA users in the content dbs) will upgrade affter FBA is configured ( I haven't tried this yet sorting my error log one error at a time). The Particular content dbs with an issue are shared services and the main site collection db which includes my sites site collections also.

[psconfigui] [SPConfigurationDatabaseSequence2] [INFO] [9/30/2010 3:44:42 PM]: SPConfigurationDatabase Name=SharePoint_Config
[psconfigui] [SPConfigurationDatabaseSequence2] [WARNING] [9/

Trying to Retain Values in a FormView When Validations fails or the SQL Fails on an Insert


To me this should be much easier, but I can't seem to retain the values that are put in the Insert template upon a validation failure or when the sql fails. This will prevent the user from having to retype everything agin in the event of a failure.

As you can see I am using the Sub Insert_Click and not using an insert through the wizard. so the fields are unbound textboxes on the form. There are 2 dropdowns that provide choices for the other fields.

Any help would be appreciated. I pasted in the code using the text only option becuase the format was getting messed up. I porboably need more background on why the fields are blanking out.



See Code below



Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

' Dim sqlparm As String

Dim con As Data.SqlClient.SqlConnection = Nothing

Dim cmd As Data.SqlClient.SqlCommand = Nothing

Dim dr As Data.SqlClient.SqlDataReader = Nothing

Dim sql As String = ""

Dim x As Integer

' Dim x As Integer



If CType(Me.fvwAppSecurityDetails.FindControl("CorpIDTextBox"), TextBox).Text = "" Then

Me.lblMessage.Text = "CorpID cannot be blank"

Exit Try

Else : Page.Session("CorpID&

JDBC - How can I get it to not throw an exception on ResultSet.isLast()?


Is there some way to configure the Sql Server JDBC driver, or parameters on the Connection or prepareStatement() so that ResultSet.isLast() can be called when I call a stored procedure that returns a ResultSet?

thanks - dave

Very funny video - What's your Metaphor?




I am working on BUlk Insert from a file to a table in SQL server 2005.



EmpName Varchar(20),

EmpAge Varchar(3),


Exception with MS-SQL Server,JDBC and XA Transactions


Hi, I'm getting the following exception in my log when I try to perform an XA transaction:

javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc_SQLServerException: failed to create the XA control connection. Error: "The EXECUTE permission was denied on the object 'xp_sqljdbc_xa_init_ex', database 'master' schema 'dbo'

I followed these tutorials Understanding XA Transactions and How to make MSSQL Server XA Datasource Work? After following the first tutorial I also ran the following command in SSMS:

(change) use master GO
EXEC sp_addrolemember [SqlJDBCXAUser], 'MyUserName' GO

I'll also add that I ran

use master GO EXEC sp_gratdbaccess 'MyUserName','MyUserName' GO

to verify that the user has access to the master db and I got an error that "the user already exists in the current database". Lastly I verified, via SSMS, that the role SqlJDBCXAUser does have EXECUTE granted in regard to xp_sqljdbc_xa_init_ex .
The DB I'm using is obviously not maste

JDBC:How I can Insert multibyte data into NTEXT field after setting SendStringParametersAsUnicode=fa

My OS : Windows XP
JDBC driver : SQL server 2005 JDBC driver 1.2
Connection string :jdbc:sqlserver://servername\SQLEXPRESS:1433;sendStringParametersAsUnicode=false

In our DB we have   a set of tables having VARCHAR and NVARCHAR , TEXT andNTEXT fields..
We have indexes using VARCHAR fields and NVARCHAR fields in various tables.
If we don't use sendStringParametersAsUnicode, by default takes as true and send every string in unicode format. This craetes issues for our tables with VARCHAR indices. Performance dropped.

So we set sendStringParametersAsUnicode=false, in our connection string. And used

setNString for 2.0 driver for NCHAR/NVARCHAR
for 1.1. and 1.2 driver we used setBytes(ordinal, data.getBytes("UTF-16LE")); since no support for NString

This is working for NCHAR/NVARCHAR types and we are able to store  multibyte data.

But the problem comes when we use stream to store data in NTEXT fields. When we use setCharacterStream() only ASCII data is stored properly. Multibytedata is corrupted
 We tried
byteInputStream = new ByteArrayInputStream(data.getBytes("UTF-16

Execution of User Defined Function fails with JDBC, when selectMethod=cursor is enabled



When I try to execute  a function using CallableStatement after setting selectMethod=cursor, it throws error com.microsoft.sqlserver.jdbc.SQLServerException: The request for procedure 'MYFUNCTION' failed because 'MYFUNCTION' is a function object. ErrorCode:2809 SQLState:S0001


If I remove selectMethod=cursor, the function is executing properly

Client details

JDBC driver : JDBC driver 3.0(sqljdbc4.jar)

Tested with JDBC driver for SQL server 2005 SP2 al;so.

OS : Windows XP Professiional


java version "1.6.0_22"

Java(TM) SE Runtime Environment (build 1.6.0_22-b04)

Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode)


Server details

SQL Server 2005(Microsoft SQL Server 2005 - 9.00.2047.00 (Intel X86)   Apr 14 2006 01:12:25   Copyright (c) 1988-2005 Microsoft Corporation  Express Edition on Windows NT 5.1 (Build 2600: Service Pack 3) )


Did somebody face this? How to solve it?

We need selectMethod=cursor because of issue mentioned here(http://connect.microsoft.com/SQLServer/feedback/details/295907/resultsetmetadata-gettablename-returns-null-or-inconsistent-results) and the solution as suggested.



Insert value using Table Value Functions

a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.


Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

Insert Rows with a GridView

In ASP.NET version 1.x, I used the footer on the DataGrid control to insert new rows by placing a series of TextBox, DropDownLists, CheckBoxes etc. controls on it and then handling a save button. This also works with the GridView in version 2.0 but with one major exception: if your data source is empty, the GridView will hide your footer (and header) and only display the EmptyDataText.

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

Sometimes you end up with a return value of -1 when using the SqlClient.SqlCommand.ExecuteNonQuery method.

Why is that?

Well, the ExecuteNonQuery method is there for statements for changing data, ie. DELETE / UPDATE /INSERT, and the returned value are the number of rows affected by that statement.

When checking the documentation we can see that there are some conditions that return -1.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of

rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

Insert Error not helpful



I am using VS2010

When I try to updated or insert a record in my User table I am getting an error that does not make sense to me and I cannot figure out what is wrong.

Also, when I try to insert a new record I get a validation error saying that the Id is required. However it is an identity field in the db so it should not be necessary to send it to the server.

Could you please shed some light?


An error has occurred.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.Web.UI.WebControls.EntityOperationException: An error has occurred.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace:

[EntityOperationException: An error has occurred.]
   Microsoft.Web.UI.WebControls.DomainDataSourceView.PerformCudOperation(ChangeSetEntry operation, Action`1 operationPerformingEvent, Action`1 operationPerformedEvent) +331
   Microsoft.Web.UI.WebControls.DomainDataSourceView.UpdateObject(Object oldEntity, O

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend