Nullpointexeption on database query
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
add a comment |
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
What if your first query doesn't match anything? Thensupername
would benull
.
– 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
add a comment |
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
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
java nullpointerexception access
asked Nov 15 '18 at 23:38
Alex GalvisAlex Galvis
187
187
What if your first query doesn't match anything? Thensupername
would benull
.
– 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
add a comment |
What if your first query doesn't match anything? Thensupername
would benull
.
– 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
add a comment |
1 Answer
1
active
oldest
votes
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
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 exampleif (va!= null && !va.equals("")) { // va is not null } else { // va is null }
– S. Mohamad
Nov 18 '18 at 18:40
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 exampleif (va!= null && !va.equals("")) { // va is not null } else { // va is null }
– S. Mohamad
Nov 18 '18 at 18:40
add a comment |
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
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 exampleif (va!= null && !va.equals("")) { // va is not null } else { // va is null }
– S. Mohamad
Nov 18 '18 at 18:40
add a comment |
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
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
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 exampleif (va!= null && !va.equals("")) { // va is not null } else { // va is null }
– S. Mohamad
Nov 18 '18 at 18:40
add a comment |
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 exampleif (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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What if your first query doesn't match anything? Then
supername
would benull
.– 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