mport java.sql.*;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Properties;
/**
* @title: text
* @Author
* @Date: 2021/10/28 8:47
* @Version 1.0
*/
public class text {
public static void main(String[] args) throws SQLException {
Driver driver=new com.mysql.cj.jdbc.Driver();
String ur ="url:jdbc:mysql://localhost:3306/text001" ;
Properties info =new Properties();
info.setProperty("user","root");
info.setProperty("password","123");
Connection con=driver.connect(ur,info);
System.out.println(con);
String sql="select * from user";
PreparedStatement ps=con.prepareStatement(sql);
ResultSet resultSet=ps.executeQuery();
ArrayList<User> list=new ArrayList<>();
while (resultSet.next()){
int id =resultSet.getInt("id");
String name =resultSet.getString("name");
int age =resultSet.getInt("age");
User user=new User(id,name,age);
list.add(user);
}
for (User user:list){
System.out.println(user.toString());
}
resultSet.close();
ps.close();
con.close();
}
}
null
Exception in thread "main" java.lang.NullPointerException
at cn.jdbctext.text.main(text.java:28)
Process finished with exit code 1