package utils;
import com.mchange.v2.lang.ObjectUtils;
import java.sql.*;
import java.util.Objects
/**
- @类名: publicss
- @说明: TODO
- @作者: xm 王一冷出品
- @时间:2019/10/11 15:13
- @版本:1.0
*/
public class publicss {
private static String url=“jdbc:mysql://localhost:3306/yonghushouquan”;
private static String username =“root”;
private static String password=“root”;
public static void main(String[] args){
//加载驱动
try {
Class.forName(“com.mysql.jdbc.Driver”);
} catch(ClassNotFoundException e){
e.getException();
}
//建立连接
try {
Connection connection = DriverManager.getConnection(url,username,password);
//预处理sql 语句
PreparedStatement preparedstatement= connection.prepareStatement(“select * from t_user”);
//接收结果集
ResultSet resultSet=preparedstatement.executeQuery();
//处理结果集
while(resultSet.next()){
System.out.print(resultSet.getInt(1)+" “);
System.out.print(resultSet.getString(2)+” “);
System.out.println(resultSet.getString(3)+” ");
}
//释放资源
if (!Objects.isNull(resultSet)){
resultSet.close();
}
if (!Objects.isNull(preparedstatement)){
preparedstatement.close();
}
if (!Objects.isNull(connection)){
connection.close();
}
} catch (SQLException e1) {
e1.printStackTrace();
}