[英]What's the simplest way to store data from a java program to MySQL?
I want to store data in string form to MySQL.我想以字符串形式将数据存储到 MySQL。 I have created the tables in the MySQL.
我已经在 MySQL 中创建了表。 I haven't worked with DATABASE ever.
我从来没有使用过数据库。 Can you please provide me code to store that data in the MySQL DB.
能否请您提供代码将该数据存储在 MySQL 数据库中。 eg Let's say I have a string "stack_overflow" and there is a column "SiteName" in a table "SiteDetails" in the DataBase.
例如,假设我有一个字符串“stack_overflow”,并且在数据库的“SiteDetails”表中有一列“SiteName”。 So how to store the string "stack_overflow" in the column "SiteName".
那么如何在“SiteName”列中存储字符串“stack_overflow”。
You should start from the Java JDBC tutorial .您应该从 Java JDBC 教程开始。 After you understand what is happening there you will need a JDBC driver for MySQL.
了解那里发生的情况后,您将需要一个用于 MySQL 的 JDBC 驱动程序。
I suggest reading about a few technologies so you can learn the framework ways of doing this stuff.我建议阅读一些技术,以便您可以了解执行这些操作的框架方法。 Such as JPA or OJB .
例如JPA或OJB 。 However, to directly answer your question, the easiest way would be with straight SQL over a JDBC connection.
但是,要直接回答您的问题,最简单的方法是通过 JDBC 连接直接使用 SQL。
insert into SiteDetails (ID, SiteName)
values(1, 'stackoverflow')
or要么
update SiteDetails
set SiteName = 'stackoverflow'
where ID = 1
I would look at the Hibernate project.我会看看 Hibernate 项目。 While it may not be simpler right now, as your application grows it will prove to be a life saver.
虽然它现在可能并不简单,但随着您的应用程序的增长,它将被证明是一个救命稻草。 Hibernate.org
休眠网站
There is iBatis which works great and gives you control of your query iBatis 效果很好,可以让你控制你的查询
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.