PreparedStatement Disallowed implicit conversion

PreparedStatement Disallowed implicit conversion

Post by Good » Sat, 08 Mar 2003 00:37:46



PreparedStatment seems to have a feature that when setting
a string that is over 4000
during execution it converts the string into NTEXT instead
of VARCHAR leaving me with the exception:

java.sql.SQLException: [Microsoft][SQLServer JDBC
Driver][SQLServer]Disallowed implicit conversion from data
type ntext to data type varchar, table
'testDB.dbo.testtablex', column 'bigstringx'. Use the
CONVERT function to run this query.
at
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown
Source)
at
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown
Source)
at
com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown
Source)
at
com.microsoft.jdbc.base.BaseStatement.executeInternal(Unknown
Source)
at
com.microsoft.jdbc.base.BasePreparedStatement.execute(Unknown
Source)
at com.inventa.schema.Test.main(Test.java:71)

For example

PreparedStatement ps = conn.prepareStatement("insert into
testtablex values(?)");
ps.setString(1, bigString);
ps.execute();

The column of the table I am trying to insert into is a
VARCHAR(7500) .

if I insert it like this

PreparedStatement ps = conn.prepareStatement("insert into
testtablex values(?)");
ps.setString(1, bigString.substring(0, 4000));
ps.execute();

it works and if I insert like this it works as well.

PreparedStatement ps = conn.prepareStatement("INSERT INTO
testtablex VALUES (CONVERT(VARCHAR(7500), ?)");
ps.setString(1, bigString);
ps.execute();

Unfortunatly I am looking for a solution where I can change
the behavior of the conversion of strings longer than 4000
to be VARCHAR for the PreparedStatement.

Has any one seen this problem or solved this problem
without switching blobs or ntext?

 
 
 

PreparedStatement Disallowed implicit conversion

Post by Danu » Sat, 08 Mar 2003 01:17:43


The issue might be in the Java driver you use.
I remember I had the same problem when I was using OleDB consumer templates
and C++.

The way I fixed it was to derive from the OleDb Template and overwrite the
method that was binding the VARCHARs bigger than 1,000 (?) to TEXT/BLOB. I
could do that because the ole-db consumer templates code is provided with
MSDEV installation. I do not know if you have acces to the Java data access
driver.

Danut


PreparedStatment seems to have a feature that when setting
a string that is over 4000
during execution it converts the string into NTEXT instead
of VARCHAR leaving me with the exception:

java.sql.SQLException: [Microsoft][SQLServer JDBC
Driver][SQLServer]Disallowed implicit conversion from data
type ntext to data type varchar, table
'testDB.dbo.testtablex', column 'bigstringx'. Use the
CONVERT function to run this query.
at
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown
Source)
at
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknow
n
Source)
at
com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown
Source)
at
com.microsoft.jdbc.base.BaseStatement.executeInternal(Unknown
Source)
at
com.microsoft.jdbc.base.BasePreparedStatement.execute(Unknown
Source)
at com.inventa.schema.Test.main(Test.java:71)

For example

PreparedStatement ps = conn.prepareStatement("insert into
testtablex values(?)");
ps.setString(1, bigString);
ps.execute();

The column of the table I am trying to insert into is a
VARCHAR(7500) .

if I insert it like this

PreparedStatement ps = conn.prepareStatement("insert into
testtablex values(?)");
ps.setString(1, bigString.substring(0, 4000));
ps.execute();

it works and if I insert like this it works as well.

PreparedStatement ps = conn.prepareStatement("INSERT INTO
testtablex VALUES (CONVERT(VARCHAR(7500), ?)");
ps.setString(1, bigString);
ps.execute();

Unfortunatly I am looking for a solution where I can change
the behavior of the conversion of strings longer than 4000
to be VARCHAR for the PreparedStatement.

Has any one seen this problem or solved this problem
without switching blobs or ntext?

 
 
 

1. PreparedStatement Disallowed implicit conversion

PreparedStatment seems to have a feature that when setting
a string that is over 4000
during execution it converts the string into NTEXT instead
of VARCHAR leaving me with the exception:

java.sql.SQLException: [Microsoft][SQLServer JDBC
Driver][SQLServer]Disallowed implicit conversion from data
type ntext to data type varchar, table
'testDB.dbo.testtablex', column 'bigstringx'. Use the
CONVERT function to run this query.
at
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown
Source)
at
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown
Source)
at
com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown
Source)
at
com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown
Source)
at
com.microsoft.jdbc.base.BaseStatement.executeInternal(Unknown
Source)
at
com.microsoft.jdbc.base.BasePreparedStatement.execute(Unknown
Source)
at com.inventa.schema.Test.main(Test.java:71)

For example

PreparedStatement ps = conn.prepareStatement("insert into
testtablex values(?)");
ps.setString(1, bigString);
ps.execute();

The column of the table I am trying to insert into is a
VARCHAR(7500) .

if I insert it like this

PreparedStatement ps = conn.prepareStatement("insert into
testtablex values(?)");
ps.setString(1, bigString.substring(0, 4000));
ps.execute();

it works and if I insert like this it works as well.

PreparedStatement ps = conn.prepareStatement("INSERT INTO
testtablex VALUES (CONVERT(VARCHAR(7500), ?)");
ps.setString(1, bigString);
ps.execute();

Unfortunatly I am looking for a solution where I can change
the behavior of the conversion of strings longer than 4000
to be VARCHAR for the PreparedStatement.

Has any one seen this problem or solved this problem
without switching blobs or ntext?

2. Sybase FAQ?

3. Disallowed implicit conversion from data type nvarchar to data type money

4. Tool for manage permissions on columns

5. SQL Server Bug: Erroneous 'Disallowed implicit conversion' error

6. SQL 7.0 Generate SQL Scripts with Dependent Objects

7. Disallowed implicit conversion from datatype 'varchar' to datatype 'int'

8. US-North Carolina-Jr. Oracle DBA Needed

9. Need help with implicit varchar -> datetime conversion

10. Implicit conversion problem

11. nvarchar to bit implicit conversion

12. Implicit conversion from int to char error

13. Peculiar and misleading implicit conversion