导入 Pom.xml依拉文件
mysql
mysql-connector-java
5.1.27
public static void main(String[] args) {
String url=“jdbc:mysql://localhost:3306/gmall2018”;
String user=“root”;
String password=“123”;
try {
Connection conn=null;
Statement st=null;
ResultSet rs=null;
//1.加载驱动程序
Class.forName(“com.mysql.jdbc.Driver”);
//2.获得数据库链接
conn= DriverManager.getConnection(url,user,password);
//3.通过数据库的连接操作数据库,实现增删改查(使用Statement类)
st=conn.createStatement();
rs=st.executeQuery(“select * from t_mall_user_account”);
//4.处理数据库的返回结果(使用ResultSet类)
while (rs.next()){
String name=rs.getString(“yh_mch”);
System.out.println(name);
}
//关闭资源
rs.close();
st.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}finally {
}
}