Nullpointexeption on database query












-1















I have a button with the following code.



 private void jLabel72MouseClicked(java.awt.event.MouseEvent evt) {                                      
newtl = managertran.getSelectedItem().toString();
vaup = va.toUpperCase();
try {
con2 = Connectionz.getConnection();//Connection Object
pst4 = con2.prepareStatement("SELECT [VA #] FROM [Login_Users] WHERE [Full Name] =?");
pst4.setString(1, newtl);
rs4 = pst4.executeQuery();
if (rs4.next()) {
newtlva = rs4.getString("VA #");
con2.close();

} }
catch (Exception ex) {
System.out.println("" + ex);
}
agentext = agentex1.getText();
try {
con2 = Connectionz2.getConnection();//Connection Object
pst4 = con2.prepareStatement("SELECT * FROM [First_Entry] WHERE [VA_Agent] =?");
pst4.setString(1, agentext);
rs4 = pst4.executeQuery();
if (rs4.next()) {
exagentname = rs4.getString("Name_Agent");
supername = rs4.getString("TL_Agent");
con2.close();

}
} catch (Exception ex) {
System.out.println("" + ex);
JOptionPane.showMessageDialog(null, "No change was done, no entries were found.1");
}
if (supername.equalsIgnoreCase(vaup)) {
try {
int yesorno2 = JOptionPane.showConfirmDialog(null, "Are you sure that you would like to change the user " + exagentname + " to the team lead " + newtl + "?", "exit", JOptionPane.YES_NO_OPTION);
if (yesorno2 == 0) {
con2 = Connectionz2.getConnection();
String exchangeag = "UPDATE [First_Entry] SET [TL_Agent] =? WHERE [VA_Agent] =? AND [TL_Agent] =?";
con2 = Connectionz2.getConnection();
pst2 = con2.prepareStatement(exchangeag);
pst2.setString(1, newtlva);
pst2.setString(2, agentext);
pst2.setString(3, vaup);
pst2.execute();
JOptionPane.showMessageDialog(null, "Done!");
agentex1.setText(" ");

}
} catch (HeadlessException | SQLException | NullPointerException ex) {
System.out.println("" + ex);
JOptionPane.showMessageDialog(null, "No change was done, no entries were found.");

}
} else {
JOptionPane.showMessageDialog(null, "You Don't have the enough privileges to change this agent");

}


To resume the code goes to a database gather a couple information provided previously with a textbox and a combobox, and change and update another entries who has the condition, the situation is that not always the database that should be updated has an user created then it is unable to find what's the register that this should update, so I'm reciving the error Exception in thread "AWT-



EventQueue-0" java.lang.NullPointerException
at Signin_Panel.jLabel72MouseClicked(Signin_Panel.java:3994)


that is the line



   if (supername.equalsIgnoreCase(vaup)) 


I Would like to be able to send a message informing that there is not user that the system cannot complete the action but I'm unable to catch where the exception is triggered, so I'm unable to show the message, I'm a newbie developer so, please don't be that hard with me any good feedback is welcome! thanks!










share|improve this question























  • What if your first query doesn't match anything? Then supername would be null.

    – Elliott Frisch
    Nov 15 '18 at 23:47











  • No, actually the one who in some cases is null is va is null then vaup is null, what I'm trying to do it's catch the error and display a message informing that there is nothing to move because va doesn't exist.

    – Alex Galvis
    Nov 18 '18 at 18:11
















-1















I have a button with the following code.



 private void jLabel72MouseClicked(java.awt.event.MouseEvent evt) {                                      
newtl = managertran.getSelectedItem().toString();
vaup = va.toUpperCase();
try {
con2 = Connectionz.getConnection();//Connection Object
pst4 = con2.prepareStatement("SELECT [VA #] FROM [Login_Users] WHERE [Full Name] =?");
pst4.setString(1, newtl);
rs4 = pst4.executeQuery();
if (rs4.next()) {
newtlva = rs4.getString("VA #");
con2.close();

} }
catch (Exception ex) {
System.out.println("" + ex);
}
agentext = agentex1.getText();
try {
con2 = Connectionz2.getConnection();//Connection Object
pst4 = con2.prepareStatement("SELECT * FROM [First_Entry] WHERE [VA_Agent] =?");
pst4.setString(1, agentext);
rs4 = pst4.executeQuery();
if (rs4.next()) {
exagentname = rs4.getString("Name_Agent");
supername = rs4.getString("TL_Agent");
con2.close();

}
} catch (Exception ex) {
System.out.println("" + ex);
JOptionPane.showMessageDialog(null, "No change was done, no entries were found.1");
}
if (supername.equalsIgnoreCase(vaup)) {
try {
int yesorno2 = JOptionPane.showConfirmDialog(null, "Are you sure that you would like to change the user " + exagentname + " to the team lead " + newtl + "?", "exit", JOptionPane.YES_NO_OPTION);
if (yesorno2 == 0) {
con2 = Connectionz2.getConnection();
String exchangeag = "UPDATE [First_Entry] SET [TL_Agent] =? WHERE [VA_Agent] =? AND [TL_Agent] =?";
con2 = Connectionz2.getConnection();
pst2 = con2.prepareStatement(exchangeag);
pst2.setString(1, newtlva);
pst2.setString(2, agentext);
pst2.setString(3, vaup);
pst2.execute();
JOptionPane.showMessageDialog(null, "Done!");
agentex1.setText(" ");

}
} catch (HeadlessException | SQLException | NullPointerException ex) {
System.out.println("" + ex);
JOptionPane.showMessageDialog(null, "No change was done, no entries were found.");

}
} else {
JOptionPane.showMessageDialog(null, "You Don't have the enough privileges to change this agent");

}


To resume the code goes to a database gather a couple information provided previously with a textbox and a combobox, and change and update another entries who has the condition, the situation is that not always the database that should be updated has an user created then it is unable to find what's the register that this should update, so I'm reciving the error Exception in thread "AWT-



EventQueue-0" java.lang.NullPointerException
at Signin_Panel.jLabel72MouseClicked(Signin_Panel.java:3994)


that is the line



   if (supername.equalsIgnoreCase(vaup)) 


I Would like to be able to send a message informing that there is not user that the system cannot complete the action but I'm unable to catch where the exception is triggered, so I'm unable to show the message, I'm a newbie developer so, please don't be that hard with me any good feedback is welcome! thanks!










share|improve this question























  • What if your first query doesn't match anything? Then supername would be null.

    – Elliott Frisch
    Nov 15 '18 at 23:47











  • No, actually the one who in some cases is null is va is null then vaup is null, what I'm trying to do it's catch the error and display a message informing that there is nothing to move because va doesn't exist.

    – Alex Galvis
    Nov 18 '18 at 18:11














-1












-1








-1








I have a button with the following code.



 private void jLabel72MouseClicked(java.awt.event.MouseEvent evt) {                                      
newtl = managertran.getSelectedItem().toString();
vaup = va.toUpperCase();
try {
con2 = Connectionz.getConnection();//Connection Object
pst4 = con2.prepareStatement("SELECT [VA #] FROM [Login_Users] WHERE [Full Name] =?");
pst4.setString(1, newtl);
rs4 = pst4.executeQuery();
if (rs4.next()) {
newtlva = rs4.getString("VA #");
con2.close();

} }
catch (Exception ex) {
System.out.println("" + ex);
}
agentext = agentex1.getText();
try {
con2 = Connectionz2.getConnection();//Connection Object
pst4 = con2.prepareStatement("SELECT * FROM [First_Entry] WHERE [VA_Agent] =?");
pst4.setString(1, agentext);
rs4 = pst4.executeQuery();
if (rs4.next()) {
exagentname = rs4.getString("Name_Agent");
supername = rs4.getString("TL_Agent");
con2.close();

}
} catch (Exception ex) {
System.out.println("" + ex);
JOptionPane.showMessageDialog(null, "No change was done, no entries were found.1");
}
if (supername.equalsIgnoreCase(vaup)) {
try {
int yesorno2 = JOptionPane.showConfirmDialog(null, "Are you sure that you would like to change the user " + exagentname + " to the team lead " + newtl + "?", "exit", JOptionPane.YES_NO_OPTION);
if (yesorno2 == 0) {
con2 = Connectionz2.getConnection();
String exchangeag = "UPDATE [First_Entry] SET [TL_Agent] =? WHERE [VA_Agent] =? AND [TL_Agent] =?";
con2 = Connectionz2.getConnection();
pst2 = con2.prepareStatement(exchangeag);
pst2.setString(1, newtlva);
pst2.setString(2, agentext);
pst2.setString(3, vaup);
pst2.execute();
JOptionPane.showMessageDialog(null, "Done!");
agentex1.setText(" ");

}
} catch (HeadlessException | SQLException | NullPointerException ex) {
System.out.println("" + ex);
JOptionPane.showMessageDialog(null, "No change was done, no entries were found.");

}
} else {
JOptionPane.showMessageDialog(null, "You Don't have the enough privileges to change this agent");

}


To resume the code goes to a database gather a couple information provided previously with a textbox and a combobox, and change and update another entries who has the condition, the situation is that not always the database that should be updated has an user created then it is unable to find what's the register that this should update, so I'm reciving the error Exception in thread "AWT-



EventQueue-0" java.lang.NullPointerException
at Signin_Panel.jLabel72MouseClicked(Signin_Panel.java:3994)


that is the line



   if (supername.equalsIgnoreCase(vaup)) 


I Would like to be able to send a message informing that there is not user that the system cannot complete the action but I'm unable to catch where the exception is triggered, so I'm unable to show the message, I'm a newbie developer so, please don't be that hard with me any good feedback is welcome! thanks!










share|improve this question














I have a button with the following code.



 private void jLabel72MouseClicked(java.awt.event.MouseEvent evt) {                                      
newtl = managertran.getSelectedItem().toString();
vaup = va.toUpperCase();
try {
con2 = Connectionz.getConnection();//Connection Object
pst4 = con2.prepareStatement("SELECT [VA #] FROM [Login_Users] WHERE [Full Name] =?");
pst4.setString(1, newtl);
rs4 = pst4.executeQuery();
if (rs4.next()) {
newtlva = rs4.getString("VA #");
con2.close();

} }
catch (Exception ex) {
System.out.println("" + ex);
}
agentext = agentex1.getText();
try {
con2 = Connectionz2.getConnection();//Connection Object
pst4 = con2.prepareStatement("SELECT * FROM [First_Entry] WHERE [VA_Agent] =?");
pst4.setString(1, agentext);
rs4 = pst4.executeQuery();
if (rs4.next()) {
exagentname = rs4.getString("Name_Agent");
supername = rs4.getString("TL_Agent");
con2.close();

}
} catch (Exception ex) {
System.out.println("" + ex);
JOptionPane.showMessageDialog(null, "No change was done, no entries were found.1");
}
if (supername.equalsIgnoreCase(vaup)) {
try {
int yesorno2 = JOptionPane.showConfirmDialog(null, "Are you sure that you would like to change the user " + exagentname + " to the team lead " + newtl + "?", "exit", JOptionPane.YES_NO_OPTION);
if (yesorno2 == 0) {
con2 = Connectionz2.getConnection();
String exchangeag = "UPDATE [First_Entry] SET [TL_Agent] =? WHERE [VA_Agent] =? AND [TL_Agent] =?";
con2 = Connectionz2.getConnection();
pst2 = con2.prepareStatement(exchangeag);
pst2.setString(1, newtlva);
pst2.setString(2, agentext);
pst2.setString(3, vaup);
pst2.execute();
JOptionPane.showMessageDialog(null, "Done!");
agentex1.setText(" ");

}
} catch (HeadlessException | SQLException | NullPointerException ex) {
System.out.println("" + ex);
JOptionPane.showMessageDialog(null, "No change was done, no entries were found.");

}
} else {
JOptionPane.showMessageDialog(null, "You Don't have the enough privileges to change this agent");

}


To resume the code goes to a database gather a couple information provided previously with a textbox and a combobox, and change and update another entries who has the condition, the situation is that not always the database that should be updated has an user created then it is unable to find what's the register that this should update, so I'm reciving the error Exception in thread "AWT-



EventQueue-0" java.lang.NullPointerException
at Signin_Panel.jLabel72MouseClicked(Signin_Panel.java:3994)


that is the line



   if (supername.equalsIgnoreCase(vaup)) 


I Would like to be able to send a message informing that there is not user that the system cannot complete the action but I'm unable to catch where the exception is triggered, so I'm unable to show the message, I'm a newbie developer so, please don't be that hard with me any good feedback is welcome! thanks!







java nullpointerexception access






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 23:38









Alex GalvisAlex Galvis

187




187













  • What if your first query doesn't match anything? Then supername would be null.

    – Elliott Frisch
    Nov 15 '18 at 23:47











  • No, actually the one who in some cases is null is va is null then vaup is null, what I'm trying to do it's catch the error and display a message informing that there is nothing to move because va doesn't exist.

    – Alex Galvis
    Nov 18 '18 at 18:11



















  • What if your first query doesn't match anything? Then supername would be null.

    – Elliott Frisch
    Nov 15 '18 at 23:47











  • No, actually the one who in some cases is null is va is null then vaup is null, what I'm trying to do it's catch the error and display a message informing that there is nothing to move because va doesn't exist.

    – Alex Galvis
    Nov 18 '18 at 18:11

















What if your first query doesn't match anything? Then supername would be null.

– Elliott Frisch
Nov 15 '18 at 23:47





What if your first query doesn't match anything? Then supername would be null.

– Elliott Frisch
Nov 15 '18 at 23:47













No, actually the one who in some cases is null is va is null then vaup is null, what I'm trying to do it's catch the error and display a message informing that there is nothing to move because va doesn't exist.

– Alex Galvis
Nov 18 '18 at 18:11





No, actually the one who in some cases is null is va is null then vaup is null, what I'm trying to do it's catch the error and display a message informing that there is nothing to move because va doesn't exist.

– Alex Galvis
Nov 18 '18 at 18:11












1 Answer
1






active

oldest

votes


















0














I don't think it's a problem with the query. The null pointer exception is on this function supername.equalsIgnoreCase(vaup) so you have to check what is the value of this function and in particular the value of vaup (vaup = va.toUpperCase();, is va not null?)



Regards






share|improve this answer
























  • Mohamad! thanks for your response, yes actually there is some cases that va is null (when no entry was created yet for that specific user), I would like to show a pop-up noticing that but I'm unable to find the way to create the condition for that pop-up, I'm only receiving the error at the console.

    – Alex Galvis
    Nov 18 '18 at 18:10











  • You can simply add an if on the top of the function, for example if (va!= null && !va.equals("")) { // va is not null } else { // va is null }

    – S. Mohamad
    Nov 18 '18 at 18:40













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%2f53329381%2fnullpointexeption-on-database-query%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I don't think it's a problem with the query. The null pointer exception is on this function supername.equalsIgnoreCase(vaup) so you have to check what is the value of this function and in particular the value of vaup (vaup = va.toUpperCase();, is va not null?)



Regards






share|improve this answer
























  • Mohamad! thanks for your response, yes actually there is some cases that va is null (when no entry was created yet for that specific user), I would like to show a pop-up noticing that but I'm unable to find the way to create the condition for that pop-up, I'm only receiving the error at the console.

    – Alex Galvis
    Nov 18 '18 at 18:10











  • You can simply add an if on the top of the function, for example if (va!= null && !va.equals("")) { // va is not null } else { // va is null }

    – S. Mohamad
    Nov 18 '18 at 18:40


















0














I don't think it's a problem with the query. The null pointer exception is on this function supername.equalsIgnoreCase(vaup) so you have to check what is the value of this function and in particular the value of vaup (vaup = va.toUpperCase();, is va not null?)



Regards






share|improve this answer
























  • Mohamad! thanks for your response, yes actually there is some cases that va is null (when no entry was created yet for that specific user), I would like to show a pop-up noticing that but I'm unable to find the way to create the condition for that pop-up, I'm only receiving the error at the console.

    – Alex Galvis
    Nov 18 '18 at 18:10











  • You can simply add an if on the top of the function, for example if (va!= null && !va.equals("")) { // va is not null } else { // va is null }

    – S. Mohamad
    Nov 18 '18 at 18:40
















0












0








0







I don't think it's a problem with the query. The null pointer exception is on this function supername.equalsIgnoreCase(vaup) so you have to check what is the value of this function and in particular the value of vaup (vaup = va.toUpperCase();, is va not null?)



Regards






share|improve this answer













I don't think it's a problem with the query. The null pointer exception is on this function supername.equalsIgnoreCase(vaup) so you have to check what is the value of this function and in particular the value of vaup (vaup = va.toUpperCase();, is va not null?)



Regards







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 23:57









S. MohamadS. Mohamad

12




12













  • Mohamad! thanks for your response, yes actually there is some cases that va is null (when no entry was created yet for that specific user), I would like to show a pop-up noticing that but I'm unable to find the way to create the condition for that pop-up, I'm only receiving the error at the console.

    – Alex Galvis
    Nov 18 '18 at 18:10











  • You can simply add an if on the top of the function, for example if (va!= null && !va.equals("")) { // va is not null } else { // va is null }

    – S. Mohamad
    Nov 18 '18 at 18:40





















  • Mohamad! thanks for your response, yes actually there is some cases that va is null (when no entry was created yet for that specific user), I would like to show a pop-up noticing that but I'm unable to find the way to create the condition for that pop-up, I'm only receiving the error at the console.

    – Alex Galvis
    Nov 18 '18 at 18:10











  • You can simply add an if on the top of the function, for example if (va!= null && !va.equals("")) { // va is not null } else { // va is null }

    – S. Mohamad
    Nov 18 '18 at 18:40



















Mohamad! thanks for your response, yes actually there is some cases that va is null (when no entry was created yet for that specific user), I would like to show a pop-up noticing that but I'm unable to find the way to create the condition for that pop-up, I'm only receiving the error at the console.

– Alex Galvis
Nov 18 '18 at 18:10





Mohamad! thanks for your response, yes actually there is some cases that va is null (when no entry was created yet for that specific user), I would like to show a pop-up noticing that but I'm unable to find the way to create the condition for that pop-up, I'm only receiving the error at the console.

– Alex Galvis
Nov 18 '18 at 18:10













You can simply add an if on the top of the function, for example if (va!= null && !va.equals("")) { // va is not null } else { // va is null }

– S. Mohamad
Nov 18 '18 at 18:40







You can simply add an if on the top of the function, for example if (va!= null && !va.equals("")) { // va is not null } else { // va is null }

– S. Mohamad
Nov 18 '18 at 18:40






















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%2f53329381%2fnullpointexeption-on-database-query%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

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues