SQL Exception: with different data types

I am getting the following error.

SQL Exception: Columns of type'DATE' cannot hold values of type'INTEGER'.

Here's the code I used to create my table.

String createBillsTable ="create table bills(billName varchar(50), dueDate date, lastPaidDate date, amountDue double, lastPaidAmount double)";

Here's the code used to insert the data.

publicvoid insertBillData(){

try{

String billName ="ElectricBill";

Date dueDate =new Date(07/15/2006);

double amountDue = 50.55;

Date lastPaidDate =new Date(06/15/2006);

double lastPaidAmount = 60.25;

String insertStatement ="insert into bills values ('" + billName +"', '" + dueDate +"', " + lastPaidDate +", " + amountDue +", " + lastPaidAmount +")";

establishConnection();

statement.execute(insertStatement);

closeConnection();

shutDownDerby();

}catch (Throwable e){

System.out.println("exception thrown:");

if (einstanceof SQLException){

printSQLError((SQLException) e);

}

else{

e.printStackTrace();

}

}

}

If I create my table with only one Date and then try and insert just one Date it works fine. I've tried inserting each of my two different dates seperately one at a time at it works fine. I've used sysouts and getClass() to verify that both my dates are in fact SQL dates before inserting and they are.

I'm doing this just as an exercise to teach myself JDBC and using Derby as my DB. SO far everything has been great until I came across this. Now I'm a bit stumped. Am I missing something obvious?

I apologize if this is just some stupid SQL question, and realize it really doesn't have much to do with Connectivity but was hoping someone could maybe spot something I'm over looking. I can post more code if needed but thought this was all that was relevent.

Message was edited by:

kefgolfs

[2867 byte] By [kefgolfsa] at [2007-10-3 2:57:46]
# 1
> Date dueDate = new Date(07/15/2006);How do you get this line to work?
el_doradoa at 2007-7-14 20:47:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

> > Date dueDate = new Date(07/15/2006);

>

> How do you get this line to work?

Well actually in my full program I have a data object that holds a java.util.date and then a method that converts it to a SQL date before I insert it. I was trying to streamline the code for my post so I imported sql.date instead and used that line RAD didn't seem to complain and didn't give me any error execpt the SQL one in my original post.

As I mentioned in the original post I checked the data type before my insert statement in the full program and they were a SQL date. I was just trying to not post too much code.

kefgolfsa at 2007-7-14 20:47:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

> I'm doing this just as an exercise to teach myself

> JDBC and using Derby as my DB. SO far everything has

> been great until I came across this. Now I'm a bit

> stumped. Am I missing something obvious?

>

Doing it as you are means that the date must match exactly the format, if any, that the database allows for insert 'text' date/time/timestamps. To do that you must first determine what your database allows. Then you use SimpleDateFormat to format a date into a string that the database accepts.

That is problematic for a number of reasons and it is just easier to use a PreparedStatement and thus you do not have to deal with it at all - see the SetTimestamp(), etc methods of that class.

> I apologize if this is just some stupid SQL question,

> and realize it really doesn't have much to do with

> Connectivity but was hoping someone could maybe spot

> something I'm over looking. I can post more code if

> needed but thought this was all that was relevent.

There are many questions posted here which are just SQL and some which don't even have anything to do with java, so even if that was the case it wouldn't matter.

jschella at 2007-7-14 20:47:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

> That is problematic for a number of reasons and it is

> just easier to use a PreparedStatement and thus you

> do not have to deal with it at all - see the

> SetTimestamp(), etc methods of that class.

Thanks jschell, I suppose you've given me the next area I need to learn more about, namely PreparedStatements.

The confusion I had with the way I was doing it was that either of my two dates worked by itself when I had just one column of type date. But as soon as I created a second column with type date then I would get the exception.

kefgolfsa at 2007-7-14 20:47:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

> The confusion I had with the way I was doing it was

> that either of my two dates worked by itself when I

> had just one column of type date. But as soon as I

> created a second column with type date then I would

> get the exception.

The code you posted has ticks around one date but not the other.

jschella at 2007-7-14 20:47:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
> The code you posted has ticks around one date but not> the other.Thank you so much jschell, that's the kind of stupid mistake I thought I was making but just couldn't manage to see myself, probably due to the fact that I had been staring at it too long.
kefgolfsa at 2007-7-14 20:47:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...