当前位置:网站首页>JDBC cannot connect to MySQL, and the error is access denied for user 'root' @ '* * *' (using password: Yes)
JDBC cannot connect to MySQL, and the error is access denied for user 'root' @ '* * *' (using password: Yes)
2022-04-23 02:00:00 【CSDN Q & A】
import small_program.linksql.Student;import small_program.linksql.utils.JDBCUtils;import java.sql.*;import java.util.ArrayList;public class StudentDaoimpl implements StudentDao { @Override public ArrayList<Student> findAll() { ArrayList<Student> students = new ArrayList<>(); Connection connection = null; Statement statement = null; ResultSet rs = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://10.200.36.189:3306/db14","root","123456"); // register , Connect // Get execution object // connection = JDBCUtils.getConnection(); statement = connection.createStatement(); // perform SQL And receive the returned result set String sql = "select * from student"; rs = statement.executeQuery(sql); // Processing results while (rs.next()) { Integer sid = rs.getInt("sid"); String name = rs.getString("name"); Integer age = rs.getInt("age"); Date date = rs.getDate("date"); Student student = new Student(sid, name, age, date); students.add(student); } } catch (Exception e) { e.printStackTrace(); } finally { JDBCUtils.close(rs,statement,connection); } return students; } @Override public Student findById(Integer id) { Student student1 = new Student(); Connection connection = null; Statement statement = null; ResultSet rs = null; try { // register , Connect // Get execution object Class.forName("com.mysql.cj.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://10.200.36.189:3306/db14","root","123456");// connection = JDBCUtils.getConnection(); statement = connection.createStatement(); // perform SQL And receive the returned result set String sql = "select * from student where sid = id"; rs = statement.executeQuery(sql); // Processing results while (rs.next()) { Integer sid = rs.getInt("sid"); String name = rs.getString("name"); Integer age = rs.getInt("age"); Date date = rs.getDate("date"); student1.setSid(sid); student1.setName(name); student1.setAge(age); student1.setBirthday(date); } } catch (Exception e) { e.printStackTrace(); } finally { JDBCUtils.close(statement,connection); return student1; } } @Override public int insert(Student student) { return 0; } @Override public int update(Student student) { return 0; } @Override public int del(Integer id) { return 0; }}
Take the answer :
It's not a password problem
版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211146414891.html
边栏推荐
猜你喜欢
ESP32使用freeRTOS的消息队列
[tutorial] how to use GCC "zero assembly" for white whoring MDK
FL studio20.8最新中文版本安装下载图文教程
How to "gracefully" measure system performance
[经验教程]支付宝余额自动转入余额宝怎么设置关闭取消支付宝余额自动转入余额宝?
How to initialize "naming and surname" in C language
Challenges often faced by client project management
Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face
【dpdk】10. Dpdk DNS learning notes
CC2541的仿真器CC Debugger使用教程
随机推荐
在使用代理IP前需要了解哪些分类?
Basic knowledge of software testing, you can meet the interviewer after reading it
不断下沉的咖啡业,是虚假的繁荣还是破局的前夜?
什么是布尔类型?
【动手学深度学习V2】循环神经网络-1.序列模型
Is CICC fortune a state-owned enterprise and is it safe to open an account
Error in face detection and signature of Tencent cloud interface
The sixth season of 2022, the perfect children's model IPA national race leads the yuanuniverse track
如何对代理IP进行分类?
Introduction to esp32 Bluetooth controller API
拨号vps会遇到什么问题?
How to install mysql-5.7.9 in RPM mode under Linux system
[tutorial] how to use GCC "zero assembly" for white whoring MDK
Unity editor hierarchy drop-down menu extension
Uncover floating-point operations hidden by the ARM compiler
How to classify proxy IP?
How to change the size of SVG pictures without width in openlayer
MySQL active / standby configuration binary log problem
J-Link RTT使用
How to "gracefully" measure system performance