This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Inserting data at runtime into Mysql using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Inserting data at runtime into Mysql using JDBC" Watch "Inserting data at runtime into Mysql using JDBC" New topic
Author

Inserting data at runtime into Mysql using JDBC

Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 189
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.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15001
    
  27

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 189
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting data at runtime into Mysql using JDBC
 
It's not a secret anymore!