aspose file tools*
The moose likes JDBC and the fly likes java.sql.SQLException: ORA-01722: invalid number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: ORA-01722: invalid number" Watch "java.sql.SQLException: ORA-01722: invalid number" New topic
Author

java.sql.SQLException: ORA-01722: invalid number

Claudia Vaz
Ranch Hand

Joined: Nov 13, 2001
Posts: 44
Hello
I am trying to do a query to a oracle database and process the information into a vector.
Here id the code:
"rs = stmt.executeQuery(comando); con.commit();
Vector vectorHab = new Vector();
while(rs.next())
{
Hashtable hashtableHab = new Hashtable();
hashtableHab.put("codigo", rs.getString("codigo"));
hashtableHab.put("nome", rs.getString("nome"));
vectorHab.addElement(hashtableHab);
}"
Unfortunately i am getting the error
"java.sql.SQLException: ORA-01722: invalid number"
I don�t understand why. Can anyone help me....
Thanks
Claudia Vaz
prabhat kumar
Ranch Hand

Joined: Apr 11, 2001
Posts: 114
post the sql query which u r executing
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

taken from here
ORA-01722 invalid number
Cause: The attempted conversion of a character string to a number failed because the character string was not a valid numeric literal. Only numeric fields or character fields containing numeric data may be used in arithmetic functions or expressions. Only numeric fields may be added to or subtracted from dates.
Action: Check the character strings in the function or expression. Check that they contain only numbers, a sign, a decimal point, and the character "E" or "e" and retry the operation.
Jamie
Claudia Vaz
Ranch Hand

Joined: Nov 13, 2001
Posts: 44
Hi
The query is:
"select * from HL where codigo>=100000 and codigo<1000000 and codigo not like '99999%'"
Thanks
Claudia Vaz
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Originally posted by Claudia Vaz:
Hi
The query is:
"select * from HL where codigo>=100000 and codigo<1000000 and codigo not like '99999%'"
Thanks
Claudia Vaz

I don't think you can't compare a String value with and number. codigo is a number and '99999%' can not be properly converted to a number for comparison. What you want to do is convert codigo to character data so you can do the comparison. So try this:
"select * from HL where codigo>=100000 and codigo<1000000 and TO_CHAR(codigo) not like '99999%'"
Jamie
[ March 04, 2002: Message edited by: Jamie Robertson ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.sql.SQLException: ORA-01722: invalid number