It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes invalid character constant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "invalid character constant" Watch "invalid character constant" New topic

invalid character constant

mary bate

Joined: Jul 30, 2004
Posts: 12
hi guys anyone can tell me what is an invalid character constant ?
i compile my jsp file and it shows me this..

Invalid character constant. String queryText = "insert into sshl_account_application (employee_name, employee_number) values ('" + request.getParameter('employee_name') + "','" + request.getParameter('employee_number') + "')" ;
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
The invalid character constant in this case is 'employee_name'. Single quotes in Java define a character constant, i.e. one character, e.g. 'a' or 'b' or '!'. 'employee_name' is a string of them so you have to use a String literal and double quotes, i.e. "employee_name".

When I said to use single quotes I meant in your SQL query string, e.g. String sql = "insert into table values ('string in sql')"; not in your Java code.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63342

Why are you not using a PreparedStatement where you don't have to deal with all the SQL quoting issues?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: invalid character constant
It's not a secret anymore!