views:

125

answers:

5

I want to store data in string form to MySQL. I have created the tables in the MySQL. I haven't worked with DATABASE ever. Can you please provide me code to store that data in the MySQL DB. e.g. Let's say I have a string "stack_overflow" and there is a column "SiteName" in a table "SiteDetails" in the DataBase. So how to store the string "stack_overflow" in the column "SiteName".

A: 

I would look at the Hibernate project. While it may not be simpler right now, as your application grows it will prove to be a life saver. Hibernate.org

Ryan Montgomery
Hibernate is not the right solution for the questioner as he mentioned that he never worked with databases.
Max
I know Hibernate is the best option for that but as I have an urgent requirement to store the data, I need the simplest solution and I can't spend time on learning the Hibernate.
Yatendra Goel
Therefore I assume they don't know SQL either. So an ORM in this case makes more sense if not for that very reason.
Ryan Montgomery
+8  A: 

You should start from the Java JDBC tutorial. After you understand what is happening there you will need a JDBC driver for MySQL.

idrosid
I see the other answers mention Hibernate and iBatis. In real-life large-scale project you will need a framework like those. However it is important, in my opinion, to first understand the basics of JDBC.
idrosid
+1  A: 

I suggest reading about a few technologies so you can learn the framework ways of doing this stuff. Such as JPA or OJB. However, to directly answer your question, the easiest way would be with straight SQL over a JDBC connection.

 insert into SiteDetails (ID, SiteName)
 values(1, 'stackoverflow')

or

update SiteDetails 
set SiteName = 'stackoverflow'
where ID = 1
Jay
+1  A: 

Use a PreparedStatement

Joe Philllips
A: 

There is iBatis which works great and gives you control of your query

MatRichard