Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Derby Database Problems....

807599Apr 8 2007 — edited Apr 8 2007
Hi,

Im trying to insert values into a database using a prepared statment... That all fine but when i commit the data that i want to be put into the database. I get the following error:

ERROR 42821: Columns of type 'INTEGER' cannot hold values of type 'CHAR'.

But I can't understand why I do get this. If you have a look at the code below you will understand why:

This is my database schema:
create table Appointments (

  Appointment_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
  Date varchar(10) not null,
  Time varchar(10) not null,
  Employee_ID varchar(30) not null,
  Property_ID INTEGER not null,
  Customer_ID INTEGER not null,
  primary key (Appointment_ID),
  foreign key (Property_ID) references Property_Details (Property_ID),
  foreign key (Customer_ID) references Customer_Details (Customer_ID),
  foreign key (Employee_ID) references Employee (Employee_ID)

);
The code compiles fine in derby with no errors.

Now here is the code for inserting values into the database:
public void addAppointmentToDatabase(Connection database) throws SQLException
        {
          int prob = Integer.parseInt(propertyID.getText());
          int cus = Integer.parseInt(customerID.getText());
         String ADD_APPOINTMENT_SQL = "INSERT INTO Appointments (Date, Time, " +
              "Employee_ID, Property_ID, Customer_ID) VALUES('"+date.getText()+"', '"+time.getText()+
          "', '"+employeeID.getText()+"', '"+prob+"', '"+cus+"')";
          addAppointmentQuery = database.prepareStatement(ADD_APPOINTMENT_SQL);
          addAppointmentQuery.execute();
          
        }
As you can see the fields that need to be and Interger are converted to int's....

I have been stuck on this for ages, any pointers/help?

Thanks

Chris
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 6 2007
Added on Apr 8 2007
2 comments
1,272 views