Keep getting null pointer exception and classnotfound exception when trying to connect my database to my log...





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















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);

}
}


}










share|improve this question























  • Add the trace of the exception in order to have better context about the problem

    – sirandy
    Nov 22 '18 at 18:05











  • although it probably isn't the issue, you used port 330 in the second attempt

    – 4dc0
    Nov 22 '18 at 18:10











  • Also the string in the first example starts with a "." which is not correct: ".com.mysql.jbdc.Driver".

    – markspace
    Nov 22 '18 at 18:21











  • I've changed both the port number on the second one and removed the "." on the first line and still, the errors occur.

    – Matthew Robinson
    Nov 26 '18 at 12:44











  • The stack trace when i print says this is my error st = con.createStatement(); and also public static void main(String args){ DBConnect connect = new DBConnect(); connect.getData(); the last line of this code

    – Matthew Robinson
    Nov 26 '18 at 13:04


















0















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);

}
}


}










share|improve this question























  • Add the trace of the exception in order to have better context about the problem

    – sirandy
    Nov 22 '18 at 18:05











  • although it probably isn't the issue, you used port 330 in the second attempt

    – 4dc0
    Nov 22 '18 at 18:10











  • Also the string in the first example starts with a "." which is not correct: ".com.mysql.jbdc.Driver".

    – markspace
    Nov 22 '18 at 18:21











  • I've changed both the port number on the second one and removed the "." on the first line and still, the errors occur.

    – Matthew Robinson
    Nov 26 '18 at 12:44











  • The stack trace when i print says this is my error st = con.createStatement(); and also public static void main(String args){ DBConnect connect = new DBConnect(); connect.getData(); the last line of this code

    – Matthew Robinson
    Nov 26 '18 at 13:04














0












0








0








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);

}
}


}










share|improve this question














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);

}
}


}







java nullpointerexception classnotfoundexception sqlexception






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 18:03









Matthew RobinsonMatthew Robinson

95




95













  • Add the trace of the exception in order to have better context about the problem

    – sirandy
    Nov 22 '18 at 18:05











  • although it probably isn't the issue, you used port 330 in the second attempt

    – 4dc0
    Nov 22 '18 at 18:10











  • Also the string in the first example starts with a "." which is not correct: ".com.mysql.jbdc.Driver".

    – markspace
    Nov 22 '18 at 18:21











  • I've changed both the port number on the second one and removed the "." on the first line and still, the errors occur.

    – Matthew Robinson
    Nov 26 '18 at 12:44











  • The stack trace when i print says this is my error st = con.createStatement(); and also public static void main(String args){ DBConnect connect = new DBConnect(); connect.getData(); the last line of this code

    – Matthew Robinson
    Nov 26 '18 at 13:04



















  • Add the trace of the exception in order to have better context about the problem

    – sirandy
    Nov 22 '18 at 18:05











  • although it probably isn't the issue, you used port 330 in the second attempt

    – 4dc0
    Nov 22 '18 at 18:10











  • Also the string in the first example starts with a "." which is not correct: ".com.mysql.jbdc.Driver".

    – markspace
    Nov 22 '18 at 18:21











  • I've changed both the port number on the second one and removed the "." on the first line and still, the errors occur.

    – Matthew Robinson
    Nov 26 '18 at 12:44











  • The stack trace when i print says this is my error st = con.createStatement(); and also public static void main(String args){ DBConnect connect = new DBConnect(); connect.getData(); the last line of this code

    – Matthew Robinson
    Nov 26 '18 at 13:04

















Add the trace of the exception in order to have better context about the problem

– sirandy
Nov 22 '18 at 18:05





Add the trace of the exception in order to have better context about the problem

– sirandy
Nov 22 '18 at 18:05













although it probably isn't the issue, you used port 330 in the second attempt

– 4dc0
Nov 22 '18 at 18:10





although it probably isn't the issue, you used port 330 in the second attempt

– 4dc0
Nov 22 '18 at 18:10













Also the string in the first example starts with a "." which is not correct: ".com.mysql.jbdc.Driver".

– markspace
Nov 22 '18 at 18:21





Also the string in the first example starts with a "." which is not correct: ".com.mysql.jbdc.Driver".

– markspace
Nov 22 '18 at 18:21













I've changed both the port number on the second one and removed the "." on the first line and still, the errors occur.

– Matthew Robinson
Nov 26 '18 at 12:44





I've changed both the port number on the second one and removed the "." on the first line and still, the errors occur.

– Matthew Robinson
Nov 26 '18 at 12:44













The stack trace when i print says this is my error st = con.createStatement(); and also public static void main(String args){ DBConnect connect = new DBConnect(); connect.getData(); the last line of this code

– Matthew Robinson
Nov 26 '18 at 13:04





The stack trace when i print says this is my error st = con.createStatement(); and also public static void main(String args){ DBConnect connect = new DBConnect(); connect.getData(); the last line of this code

– Matthew Robinson
Nov 26 '18 at 13:04












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436224%2fkeep-getting-null-pointer-exception-and-classnotfound-exception-when-trying-to-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436224%2fkeep-getting-null-pointer-exception-and-classnotfound-exception-when-trying-to-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?