• 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
Sheriff
Posts: 36031
432
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
Sheriff
Posts: 36031
432
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: 17309
11
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
Posts: 65667
129
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.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!