java 通过java从mysql表中读取行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3857145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:42:58  来源:igfitidea点击:

Read rows from a mysql table via java

javamysqljdbc

提问by Olaseni

I need sample code to read rows of data from a mysql table using java

我需要示例代码来使用 java 从 mysql 表中读取数据行

回答by Buhake Sindi

A very simple tutorial: http://www.vogella.de/articles/MySQLJava/article.html

一个非常简单的教程:http: //www.vogella.de/articles/MySQLJava/article.html

Google is your friend.

谷歌是你的朋友。

回答by rlovtang

I wouldn't recommend using the JDBC API directly, it's error prone (sooner or later you forget to close a conection) and too verbose. There are many nice layers to use on top of JDBC. If you want to write SQL, I think Spring JDBCTemplateis nice. Or better, Groovy's SQL support(if you are just bound to 'Java the platform', not 'Java the language').
Then there are object relational mappers (ORM) where you don't need to write SQL. Take a look at Hibernateand JPA

我不建议直接使用 JDBC API,它容易出错(您迟早会忘记关闭连接)并且过于冗长。在 JDBC 之上有许多很好的层可以使用。如果要写SQL,我觉得Spring JDBCTemplate不错。或者更好的是,Groovy 的 SQL 支持(如果您只是绑定到“Java 平台”,而不是“Java 语言”)。
然后是对象关系映射器 (ORM),您无需编写 SQL。看看HibernateJPA