Paul's response is exactly right, but he didn't explain why...
With the PreparedStatement.setXXX() methods, you can only set database values, the actual database datatype things. To make a very bad analogy to Java, it's sort of like a function that could only except java primitives and no Object types.
Another way of explaining it is that the database does not do string replacement into the SQL within the set methods; instead, the data value is bound to an already parsed SQL statement that has been converted into an internal object format within the database. No further interpretation of SQL is going to take place after connection.prepareStatement().
There are a very very very few drivers for which the above is not true and what you tried might have worked, but not for any of the major databases.
Mohan Samikkannu
Greenhorn
Joined: Jul 10, 2006
Posts: 2
posted
0
Thanks a lot for the timely reply
Girish kumar.v
Greenhorn
Joined: Nov 17, 2009
Posts: 8
posted
0
HI frens, i'm trying to insert multiple rows into oracle database,
the rows are in Excel sheet ,i'm fetching it and trying it to insert into database
but i'm getting a error as follows
java.sql.SQLException: ORA-01858: a non-numeric character was found where a numeric was expected
i came to know that the error is all due to the date format
i'm attaching the part of the code so that you can go through and lemme know wat is the problem in it.
public class DBInsert {
public static void main(String[] args)
{
try{
//Date row9Date=null;
//Date row15Date=null;
String filename="C:/input_1.xls";
jxl.Workbook workbook = jxl.Workbook.getWorkbook(new File(filename));
jxl.Sheet sheet=workbook.getSheet(0);
int noOfColumns=sheet.getColumns();
int noOfRowsInSheet=sheet.getRows();
System.out.println("No of columns:"+noOfColumns);
System.out.println("No of rows:"+noOfRowsInSheet);
okay i will explain the thing in more detail ...
the date format in the xls sheet is as dd/mm/yyyy hh:mm
i'm reading it as a string
now i'm trying to convert it to date as shown below
for better understanding i'll comment those points
//read content stored as string in ADATE
String ADATE=rowContents[9];
Date ACTIVATION_DATE=null;
DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm"); //this is the format i need to put in database
if(ADATE.equals("")||ADATE==null)
{
ACTIVATION_DATE=null;
}
else
{
try
{
ACTIVATION_DATE = df.parse(ADATE);
System.out.println("Today = " + df.format(ACTIVATION_DATE));
}
catch (ParseException e)
{
e.printStackTrace();
}
}
the insert query is below
Query : insert into drawings4 values('','','CAF Form','pre-paid','A SHIRL MARIA','','98861','87361','null','null','','','','','Wed Jul 02 18:30:00 IST 4','','100',51,'Bangalore')
the problem is that it is not getting converted
also the default format in the oracle is noy the same
Fatih Keles
Ranch Hand
Joined: Sep 01, 2005
Posts: 182
posted
0
As previous posts say that you should really use PreparedStatement and setDate method.
Problem : Oracle is trying to convert your date string to date using default date format and it expects a number but founds text.
Solution : Again, use PreparedStatement and setDate method.
Regards,
Fatih.
Girish kumar.v
Greenhorn
Joined: Nov 17, 2009
Posts: 8
posted
0
hi
i used the prepared statement as per you suggestion but din help it out
my problem is in converting the fetched string into date(the string format is "dd/mm/yyyy hh:mm")
how do i convert the following with the same format to be retained so that i can insert into the DB
i've also attached my code and the fragment
Thanks girish
Prabhat Jha
Ranch Hand
Joined: Aug 13, 2007
Posts: 58
posted
0
in SimpleDateFormat pass the same format as used by your database.
Thanks
Thanks,
Prabhat
SCJP 1.5, SCWCD 1.5, SCBCD 1.5
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: java.sql.SQLException: ORA-01858: a non-numeric character was found where a numeric