Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data Record to Database

 
Ekrem Altintas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to record a variable to database(MySQL).Connection established.

I have tried several kinds of syntax, but it didn't work.How is the "insert" syntax?

String abc='hello';
cumle.executeUpdate("INSERT INTO genel(id, "+"Url) VALUES(5,abc)");
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ekrem,
Welcome to JavaRanch!

You are really close. Look at how I referenced the variable abc. It is in SQL quotes so SQL references it as a String. It also is surrounded by plus signs so Java treats as a variable rather than the string "abc"

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the future, note that we have a forum near the top for JDBC/SQL/database questions.

Jeanne
JDBC Forum Bartender
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the JDBC Forum

Mark
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And to avoid problems with such quoting issues in the future, look into using PreparedStatement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic