• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Inserting data at runtime into Mysql using JDBC

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends,
I want to take inputs from console and save the data entered into the MySQL using jdbc. Following is the code I tried to make but this code is notable to enter the data into the table . It just increment the primary key.

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at line 72. You're exeuting the following SQL statement:

INSERT INTO OHRI VALUES (id ,title , author)

Note that you are not filling in the values of the variables id, title and author; instead, you're executing a statement which literally contains the names of the variables "id", "title" and "author". That's not going to work - the database is not going to understand what these words mean.

You should use a PreparedStatement instead and set the values before you execute the statement.

 
Tarun Oohri
Ranch Hand
Posts: 189
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:Look at line 72. You're exeuting the following SQL statement:

INSERT INTO OHRI VALUES (id ,title , author)

Note that you are not filling in the values of the variables id, title and author; instead, you're executing a statement which literally contains the names of the variables "id", "title" and "author". That's not going to work - the database is not going to understand what these words mean.

You should use a PreparedStatement instead and set the values before you execute the statement.



Thanks dear... got it
reply
    Bookmark Topic Watch Topic
  • New Topic