Code:
import java.sql.*;
public class DBConnect {
private Connection con;
private Statement st;
private ResultSet rs;
public DBConnect(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DataBaseName","user_name","password");
st = con.createStatement();
}catch(Exception ex){
System.out.println("Error: "+ex);
}
}
public void getData(){
try{
String query = "select * from test";
rs = st.executeQuery(query);
System.out.println("Records from Database");
while(rs.next()){
String name = rs.getString("name");
String age = rs.getString("age");
System.out.println("name: "+name+" "+"age: "+age);
}
}catch(Exception ex){
System.out.println(ex);
}
}
}
this code is written in the video, but when i run it, it gives me the error:
Error: java.sql.SQLExc eption: Access denied for user 'user_name'@'lo calhost' (using password: YES)
java.lang.NullP ointerException
what is the problem here ?
Comment