Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Implicit Conversion Error

2 posts in Internet Last posting was on 2001-01-10 15:38:03.0Z
Scott_Frolich Posted on 2001-01-10 02:14:34.0Z
From: Scott_Frolich
Date: Tue, 9 Jan 2001 21:14:34 -0500
Newsgroups: sybase.public.sqlserver.internet
Subject: Implicit Conversion Error
Message-ID: <A27F685A3F2C43D7000C51F8852569D0.000C5209852569D0@webforums>
Lines: 32
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.sqlserver.internet:269
Article PK: 1067328

Hello,
isn't it possible to use PreparedStatement.setString() when putting
values into a table that contains a integer column?

If I have a table that looks like:

Create Table ABX_OBJECTS (
ID INTEGER NOT NULL,
SEQUENCE VARCHAR(10) NOT NULL,
VALUE VARCHAR(255) NOT NULL )

and I try

String SQL = Insert Into dbo.ABX_OBJECTS (ID, SEQUENCE, VALUE) VALUES (?,
?, ?);
PreparedStatement pstmt = conn.prepareStatement(SQL);
pstmt.setString(1, "1");
pstmt.setString(1, "seq");
pstmt.setString(1, "value");
pstmt.executeUpdate();

I'll get an error on the executeUpdate()

SQL Exception: Implicit conversion from datatype 'CHAR' to 'INT' is not
allowed. Use the CONVERT function to run this query.

I'm using the JDBC 4.2 driver and connecting to a 11.5 and 12.0 server. All
other drivers that I'm using (MSSQL, Oracle, and DB2) allow this conversion
in the JDBC driver.

Thanks,
Scott


Jason Froebe Posted on 2001-01-10 15:38:03.0Z
Message-ID: <3A5C81DB.B6CB1909@sybase.com>
Date: Wed, 10 Jan 2001 09:38:03 -0600
From: Jason Froebe <jfroebe@sybase.com>
Organization: Sybase, Inc.
X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.4.0-ac4 i686)
X-Accept-Language: en
MIME-Version: 1.0
Subject: Re: Implicit Conversion Error
References: <A27F685A3F2C43D7000C51F8852569D0.000C5209852569D0@webforums>
Content-Type: multipart/mixed; boundary="------------3096375F2E9AF0DDC75D9A39"
Newsgroups: sybase.public.sqlserver.internet
Lines: 55
NNTP-Posting-Host: jfroebe-desktop.sybase.com 157.133.46.52
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub sybase.public.sqlserver.internet:264
Article PK: 1067323


Scott_Frolich wrote:

> Hello,
> isn't it possible to use PreparedStatement.setString() when putting
> values into a table that contains a integer column?
>
> If I have a table that looks like:
>
> Create Table ABX_OBJECTS (
> ID INTEGER NOT NULL,
> SEQUENCE VARCHAR(10) NOT NULL,
> VALUE VARCHAR(255) NOT NULL )
>
> and I try
>
> String SQL = Insert Into dbo.ABX_OBJECTS (ID, SEQUENCE, VALUE) VALUES (?,
> ?, ?);
> PreparedStatement pstmt = conn.prepareStatement(SQL);
> pstmt.setString(1, "1");
> pstmt.setString(1, "seq");
> pstmt.setString(1, "value");
> pstmt.executeUpdate();
>
> I'll get an error on the executeUpdate()
>
> SQL Exception: Implicit conversion from datatype 'CHAR' to 'INT' is not
> allowed. Use the CONVERT function to run this query.
>
> I'm using the JDBC 4.2 driver and connecting to a 11.5 and 12.0 server. All
> other drivers that I'm using (MSSQL, Oracle, and DB2) allow this conversion
> in the JDBC driver.
>
> Thanks,
> Scott

Hi Scott,

Um, your column numbers are incorrect. The following is the correct code
snippet.

pstmt.setInt(1, "1"); <- you can also use setString() but setInt() is
better
pstmt.setString(2, "seq");
pstmt.setString(3, "value");
pstmt.executeUpdate();

hope this helps

j


Download VCard jfroebe.vcf