I've only recently started coding in java, I have been trying to connect my phpadmin database to my java log in form in netbeans. I have tried on my own and followed solutions and tutorials to try and fix but can't seem to figure out what the issue is. I've created two forms, one with a GUI the other without and both get the same errors. I've read that the Null Pointer is when the variable hasn't been assigned a value and asked to do something and the other error is because there's no driver in the library, however, I have installed a driver into the library and in netbeans 8.2 it also comes with a jbdc driver in the pre-programmed library.
Here is my connection code for the first Log In form either way.
public class MySqlConnect {
Connection conn=null;
public static Connection ConnectDB(){
try{
Class.forName(".com.mysql.jbdc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/3306/test","root", "");
JOptionPane.showMessageDialog(null, "connected to database");
return conn;
} catch(HeadlessException | ClassNotFoundException | SQLException e){
JOptionPane.showMessageDialog(null, e);
return null;
}
} }
and my second attempt was
public class DBConnect {
private Connection con;
private Statement st;
private ResultSet rs;
public DBConnect(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jbdc:mysql://localhost:330/test","root","Smackdown1");
st = con.createStatement();
}catch(ClassNotFoundException | SQLException ex){
System.out.println(ex);
}
}
public void getData(){
try{
String query =" select * from persons";
st = con.createStatement();
rs = st.executeQuery(query);
System.out.println("Records from persons");
while(rs.next()){
String name= rs.getString("name");
String password= rs.getString("password");
System.out.println("Name:" +name+" "+"Password" +password);
}
}catch(Exception ex){
System.out.println(ex);
}
}
}