jdbc建立数据库连接的helloword
?
package com.guoguo.db;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class DBUtil {
//數(shù)據(jù)庫(kù)連接地址
private static final String URL = "jdbc:mysql://127.0.0.1:3306/spring_test";
private static final String USER = "root";
private static final String PASSWORD = "";
public static void main(String[] args) throws ClassNotFoundException,
SQLException {
// TODO 自動(dòng)生成的方法存根
// 1.加載驅(qū)動(dòng)程序
Class.forName("com.mysql.jdbc.Driver");
// 2.獲取數(shù)據(jù)庫(kù)的連接
java.sql.Connection conn=DriverManager.getConnection(URL, USER, PASSWORD);
//3.通過(guò)數(shù)據(jù)庫(kù)的連接操作數(shù)據(jù)庫(kù)
java.sql.Statement stmt=conn.createStatement();
ResultSet result=stmt.executeQuery("select name,money from account");
while (result.next()){
System.out.println(result.getString("name")+","+result.getString("money"));
}
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/guojie001/p/5650569.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的jdbc建立数据库连接的helloword的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: android p wifi一直在扫描_
- 下一篇: linux cmake编译源码,linu