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?
java sql database
add a comment |
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?
java sql database
1
Suggestion: use atry-with-resources, and then you can remove all of the.close()calls. Also, technicallyrs.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
add a comment |
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?
java sql database
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
java sql database
asked Nov 18 at 3:03
Sieccc
44
44
1
Suggestion: use atry-with-resources, and then you can remove all of the.close()calls. Also, technicallyrs.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
add a comment |
1
Suggestion: use atry-with-resources, and then you can remove all of the.close()calls. Also, technicallyrs.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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53357518%2fdisplay-name-after-user-login%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
1
Suggestion: use a
try-with-resources, and then you can remove all of the.close()calls. Also, technicallyrs.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