Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error converting data type nvarchar to float

1 view
Skip to first unread message

malkovitz

unread,
Jul 15, 2002, 5:07:56 PM7/15/02
to
Hi all,

i had this exception while trying to insert new records in MSSQL 2000 via
JDBC:


DDL for SQL 2000 (generated from SQL EM):

CREATE TABLE [dbo].[tblQuotes] (
[quoteDetailId] [int] IDENTITY (1, 1) NOT NULL ,
[quoteId] [int] NOT NULL ,
[roomDescription] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[material_desc] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[serviceDescription] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[sqFeet] [int] NULL ,
[priceSqFeet] [float] NULL ,
[trackingId] [int] NULL
) ON [PRIMARY]
GO

--------

And here is my Java code to get an object from Vector container and display
its properties:

String UPDATE_QUOTE = "INSERT INTO tblQuotes (material_desc,
roomDescription, sqFeet, priceSqFeet, quoteId, trackingId) VALUES ('?', '?',
?, ?, ?, ?);";

...

pst = con.prepareStatement(UPDATE_QUOTE);
Quote oneQuote = (Quote)finalQuote.elementAt(i);

int integerSqFeet = Integer.parseInt(oneQuote.getSqFeet());
float floatPriceSqFeet =
Float.parseFloat(oneQuote.getPriceSqFeet());
int integerQuoteId =
Integer.parseInt(oneQuote.getQuoteId());
int integerTrackingId = Integer.parseInt(trackingid);

pst.setString(1, oneQuote.getMaterialDescription());
pst.setString(2, oneQuote.getRoomDescription());
pst.setInt(3, integerSqFeet);
pst.setFloat(4, floatPriceSqFeet);
pst.setInt(5, integerQuoteId);
pst.setInt(6, integerTrackingId);
pst.execute();
pst.close();


-------------------------------------------

java.sql.SQLException: Error converting data type nvarchar to float.
Severity 16, State 5, Procedure 'DEV7 null', Line 8

at
weblogic.jdbcbase.mssqlserver4.TdsStatement.processWarning(TdsStatement.java
:1240)

at
weblogic.jdbcbase.mssqlserver4.TdsStatement.parseMsWarning(TdsStatement.java
:1151)

at
weblogic.jdbcbase.mssqlserver4.TdsStatement.getMoreResults(TdsStatement.java
:814)

at
weblogic.jdbcbase.mssqlserver4.TdsStatement.execute(TdsStatement.java:211)

at
weblogic.jdbcbase.mssqlserver4.TdsStatement.execute(TdsStatement.java:1554)

at com.ralphsflooring.at.Quotes.UpdateCustomerQuotes(Quotes.java:157)

at com.ralphsflooring.at.test.TestVector.main(TestVector.java:23)


The SQL statement executes fine in the query analyzer but what do i do
here - all fields seem to be mapped correctly ? Thanks for your help.

m.

Joseph Weinstein

unread,
Jul 16, 2002, 3:58:06 PM7/16/02
to malkovitz
Hi. Your JDBC SQL is slightly wrong. You should remove the single-quotes
around the question-marks. A question mark is a generic placeholder for any
sort of parameter. Any setXXX() call will do the right thing. Try this:

String UPDATE_QUOTE =
"INSERT INTO tblQuotes (material_desc, roomDescription, sqFeet, priceSqFeet, quoteId, trackingId)

VALUES (?, ?, ?, ?, ?, ?)";

Also note that there should not be any semicolon at the end.
Joe

malkovitz

unread,
Jul 17, 2002, 12:35:49 PM7/17/02
to
Thanks a lod - it worked

"Joseph Weinstein" <j...@bea.com> wrote in message
news:3D347ACD...@bea.com...

Joseph Weinstein

unread,
Jul 17, 2002, 12:54:43 PM7/17/02
to

malkovitz wrote:

> Thanks a lot - it worked

coolness. glad to help.
Joe

0 new messages