File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting data at runtime into Mysql using JDBC

 
Tarun Oohri
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • 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.

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 1
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic