Display Name after User Login











up vote
0
down vote

favorite












I have here a function for Login button in UserLogin Frame so whenever I press the LoginButton then it will display the User First Name and Last Name on the Another frame



String sql = "select * from User_Tablen" +
"inner join Role_Table on User_Table.Role_ID=Role_Table.Role_IDn" +
"where Username = ? and Password = ? and Role_Name = ?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
pst.setString(2, jPasswordField1.getText());
pst.setString(3, (String) RoleComboBox.getSelectedItem());

rs=pst.executeQuery();

String add1 = rs.getString("First_Name");
String add2 = rs.getString("Last_Name");
AdminPortal APP = new AdminPortal();
APP.UserName.setText("Hello : "+add1+" "+add2);
if(rs.next()){
rs.close();
pst.close();
if(RoleComboBox.getSelectedItem().toString().equals("Admin")){
JOptionPane.showMessageDialog(null, "Hello Admin","Successfully Login",JOptionPane.INFORMATION_MESSAGE);
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Receptionist")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
AdminPortal AP = new AdminPortal();
AP.setVisible(true);
this.dispose();

}else if(RoleComboBox.getSelectedItem().toString().equals("Doctor")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Nurse")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Pharmacist")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Accountant")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Laboratorist,EO")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}}
else{
JOptionPane.showMessageDialog(null, "Incorrect Input","Error",JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}finally {
try {
rs.close();
pst.close();
}catch(Exception e){

}
}


But if I press the button it say "java.sql.SQLEXCEPTION : database is locked"
the UserName variable there is public from another jframe so i can call it.
However when I try to change it into



System.out.println("Hello : "+add1+" "+add2);


This kinda work but not in the frame is there any solution for this problem?










share|improve this question


















  • 1




    Suggestion: use a try-with-resources, and then you can remove all of the .close() calls. Also, technically rs.close() can throw an Exception. So one would need to be careful about that as well.
    – KevinO
    Nov 18 at 3:10










  • TY sir, so what code should I end up sir? I am really new at this sir
    – Sieccc
    Nov 18 at 3:13










  • Code comments aside, the first issue to tackle is the locked database. What database are you using? MySQL, Postgresql, or what? Where is the connection being retrieved and closed? You might look at this question
    – KevinO
    Nov 18 at 3:18










  • I am using SQLITE sir the connection is being retrieved from another class sir
    – Sieccc
    Nov 18 at 4:49










  • Please try How do I unlock a SQLite database. That might get past the locked issue.
    – KevinO
    Nov 18 at 5:02















up vote
0
down vote

favorite












I have here a function for Login button in UserLogin Frame so whenever I press the LoginButton then it will display the User First Name and Last Name on the Another frame



String sql = "select * from User_Tablen" +
"inner join Role_Table on User_Table.Role_ID=Role_Table.Role_IDn" +
"where Username = ? and Password = ? and Role_Name = ?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
pst.setString(2, jPasswordField1.getText());
pst.setString(3, (String) RoleComboBox.getSelectedItem());

rs=pst.executeQuery();

String add1 = rs.getString("First_Name");
String add2 = rs.getString("Last_Name");
AdminPortal APP = new AdminPortal();
APP.UserName.setText("Hello : "+add1+" "+add2);
if(rs.next()){
rs.close();
pst.close();
if(RoleComboBox.getSelectedItem().toString().equals("Admin")){
JOptionPane.showMessageDialog(null, "Hello Admin","Successfully Login",JOptionPane.INFORMATION_MESSAGE);
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Receptionist")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
AdminPortal AP = new AdminPortal();
AP.setVisible(true);
this.dispose();

}else if(RoleComboBox.getSelectedItem().toString().equals("Doctor")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Nurse")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Pharmacist")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Accountant")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Laboratorist,EO")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}}
else{
JOptionPane.showMessageDialog(null, "Incorrect Input","Error",JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}finally {
try {
rs.close();
pst.close();
}catch(Exception e){

}
}


But if I press the button it say "java.sql.SQLEXCEPTION : database is locked"
the UserName variable there is public from another jframe so i can call it.
However when I try to change it into



System.out.println("Hello : "+add1+" "+add2);


This kinda work but not in the frame is there any solution for this problem?










share|improve this question


















  • 1




    Suggestion: use a try-with-resources, and then you can remove all of the .close() calls. Also, technically rs.close() can throw an Exception. So one would need to be careful about that as well.
    – KevinO
    Nov 18 at 3:10










  • TY sir, so what code should I end up sir? I am really new at this sir
    – Sieccc
    Nov 18 at 3:13










  • Code comments aside, the first issue to tackle is the locked database. What database are you using? MySQL, Postgresql, or what? Where is the connection being retrieved and closed? You might look at this question
    – KevinO
    Nov 18 at 3:18










  • I am using SQLITE sir the connection is being retrieved from another class sir
    – Sieccc
    Nov 18 at 4:49










  • Please try How do I unlock a SQLite database. That might get past the locked issue.
    – KevinO
    Nov 18 at 5:02













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have here a function for Login button in UserLogin Frame so whenever I press the LoginButton then it will display the User First Name and Last Name on the Another frame



String sql = "select * from User_Tablen" +
"inner join Role_Table on User_Table.Role_ID=Role_Table.Role_IDn" +
"where Username = ? and Password = ? and Role_Name = ?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
pst.setString(2, jPasswordField1.getText());
pst.setString(3, (String) RoleComboBox.getSelectedItem());

rs=pst.executeQuery();

String add1 = rs.getString("First_Name");
String add2 = rs.getString("Last_Name");
AdminPortal APP = new AdminPortal();
APP.UserName.setText("Hello : "+add1+" "+add2);
if(rs.next()){
rs.close();
pst.close();
if(RoleComboBox.getSelectedItem().toString().equals("Admin")){
JOptionPane.showMessageDialog(null, "Hello Admin","Successfully Login",JOptionPane.INFORMATION_MESSAGE);
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Receptionist")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
AdminPortal AP = new AdminPortal();
AP.setVisible(true);
this.dispose();

}else if(RoleComboBox.getSelectedItem().toString().equals("Doctor")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Nurse")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Pharmacist")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Accountant")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Laboratorist,EO")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}}
else{
JOptionPane.showMessageDialog(null, "Incorrect Input","Error",JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}finally {
try {
rs.close();
pst.close();
}catch(Exception e){

}
}


But if I press the button it say "java.sql.SQLEXCEPTION : database is locked"
the UserName variable there is public from another jframe so i can call it.
However when I try to change it into



System.out.println("Hello : "+add1+" "+add2);


This kinda work but not in the frame is there any solution for this problem?










share|improve this question













I have here a function for Login button in UserLogin Frame so whenever I press the LoginButton then it will display the User First Name and Last Name on the Another frame



String sql = "select * from User_Tablen" +
"inner join Role_Table on User_Table.Role_ID=Role_Table.Role_IDn" +
"where Username = ? and Password = ? and Role_Name = ?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
pst.setString(2, jPasswordField1.getText());
pst.setString(3, (String) RoleComboBox.getSelectedItem());

rs=pst.executeQuery();

String add1 = rs.getString("First_Name");
String add2 = rs.getString("Last_Name");
AdminPortal APP = new AdminPortal();
APP.UserName.setText("Hello : "+add1+" "+add2);
if(rs.next()){
rs.close();
pst.close();
if(RoleComboBox.getSelectedItem().toString().equals("Admin")){
JOptionPane.showMessageDialog(null, "Hello Admin","Successfully Login",JOptionPane.INFORMATION_MESSAGE);
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Receptionist")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
AdminPortal AP = new AdminPortal();
AP.setVisible(true);
this.dispose();

}else if(RoleComboBox.getSelectedItem().toString().equals("Doctor")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Nurse")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Pharmacist")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Accountant")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}else if(RoleComboBox.getSelectedItem().toString().equals("Laboratorist,EO")){
JOptionPane.showMessageDialog(null, "Successfully Login");
rs.close();
pst.close();
}}
else{
JOptionPane.showMessageDialog(null, "Incorrect Input","Error",JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}finally {
try {
rs.close();
pst.close();
}catch(Exception e){

}
}


But if I press the button it say "java.sql.SQLEXCEPTION : database is locked"
the UserName variable there is public from another jframe so i can call it.
However when I try to change it into



System.out.println("Hello : "+add1+" "+add2);


This kinda work but not in the frame is there any solution for this problem?







java sql database






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 at 3:03









Sieccc

44




44








  • 1




    Suggestion: use a try-with-resources, and then you can remove all of the .close() calls. Also, technically rs.close() can throw an Exception. So one would need to be careful about that as well.
    – KevinO
    Nov 18 at 3:10










  • TY sir, so what code should I end up sir? I am really new at this sir
    – Sieccc
    Nov 18 at 3:13










  • Code comments aside, the first issue to tackle is the locked database. What database are you using? MySQL, Postgresql, or what? Where is the connection being retrieved and closed? You might look at this question
    – KevinO
    Nov 18 at 3:18










  • I am using SQLITE sir the connection is being retrieved from another class sir
    – Sieccc
    Nov 18 at 4:49










  • Please try How do I unlock a SQLite database. That might get past the locked issue.
    – KevinO
    Nov 18 at 5:02














  • 1




    Suggestion: use a try-with-resources, and then you can remove all of the .close() calls. Also, technically rs.close() can throw an Exception. So one would need to be careful about that as well.
    – KevinO
    Nov 18 at 3:10










  • TY sir, so what code should I end up sir? I am really new at this sir
    – Sieccc
    Nov 18 at 3:13










  • Code comments aside, the first issue to tackle is the locked database. What database are you using? MySQL, Postgresql, or what? Where is the connection being retrieved and closed? You might look at this question
    – KevinO
    Nov 18 at 3:18










  • I am using SQLITE sir the connection is being retrieved from another class sir
    – Sieccc
    Nov 18 at 4:49










  • Please try How do I unlock a SQLite database. That might get past the locked issue.
    – KevinO
    Nov 18 at 5:02








1




1




Suggestion: use a try-with-resources, and then you can remove all of the .close() calls. Also, technically rs.close() can throw an Exception. So one would need to be careful about that as well.
– KevinO
Nov 18 at 3:10




Suggestion: use a try-with-resources, and then you can remove all of the .close() calls. Also, technically rs.close() can throw an Exception. So one would need to be careful about that as well.
– KevinO
Nov 18 at 3:10












TY sir, so what code should I end up sir? I am really new at this sir
– Sieccc
Nov 18 at 3:13




TY sir, so what code should I end up sir? I am really new at this sir
– Sieccc
Nov 18 at 3:13












Code comments aside, the first issue to tackle is the locked database. What database are you using? MySQL, Postgresql, or what? Where is the connection being retrieved and closed? You might look at this question
– KevinO
Nov 18 at 3:18




Code comments aside, the first issue to tackle is the locked database. What database are you using? MySQL, Postgresql, or what? Where is the connection being retrieved and closed? You might look at this question
– KevinO
Nov 18 at 3:18












I am using SQLITE sir the connection is being retrieved from another class sir
– Sieccc
Nov 18 at 4:49




I am using SQLITE sir the connection is being retrieved from another class sir
– Sieccc
Nov 18 at 4:49












Please try How do I unlock a SQLite database. That might get past the locked issue.
– KevinO
Nov 18 at 5:02




Please try How do I unlock a SQLite database. That might get past the locked issue.
– KevinO
Nov 18 at 5:02

















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',
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%2f53357518%2fdisplay-name-after-user-login%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357518%2fdisplay-name-after-user-login%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

Paul Cézanne

UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

Angular material date-picker (MatDatepicker) auto completes the date on focus out