File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Expected result not coming in an application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Expected result not coming in an application" Watch "Expected result not coming in an application" New topic

Expected result not coming in an application

upanshu vaid
Ranch Hand

Joined: Sep 07, 2012
Posts: 83

Hi Ranch,
Below code is one of the functionality in the application i am developing

my concern is that when i enter user id and password whether correct ,incorrect or left blank i am taken to the next frame kindly suggest on this so that i can proceed with my development
LoginInformation is the ms access database table i am using.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
User_ID = jTextField1.getText().trim();
Password = jTextField2.getText().trim();
boolean b;
try {
pstmt = con.prepareStatement("Select UserID From LoginInformation where UserId=' "+User_ID+" ' and Password=' "+Password+" ' ");
b = pstmt.execute();
HomePage hp = new HomePage();
} else if (User_ID.isEmpty() || Password.isEmpty()) {
JOptionPane.showMessageDialog(null, "UserId and password cannot be left blank.");
} else {
JOptionPane.showMessageDialog(null, "User ID and Password are not correct");
catch (Exception e) {

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33134

This is the idiom for checking if a result is returned:

Note that it calls executeQuery not execute.

Also, if this code is anything more than a toy, read up on SQL Injection. In particularly your query should be
Select UserID From LoginInformation where UserId=? and Password=?
and use pstmt.setString() to pass in the user id and password.

Similarly, if this is more than a toy, you won't want to store plain text passwords in the database.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
upanshu vaid
Ranch Hand

Joined: Sep 07, 2012
Posts: 83

Thanks for your reply

in another functionality of the same application i want to use the userid value of the previous frame which is login frame to the current frame which is welcome frame how can this be achieved.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String deposit = ("Amount Credited Successfully");
k = jTextField1.getText().trim();
j = Integer.parseInt(k);
try {

if (j > 0) {
f1 = f1 + j;
h = String.valueOf(f1);
pstmnt = con.prepareStatement("Update Transaction set deposit=? where User_ID=?");

pstmnt.setString(1, h);
JOptionPane.showMessageDialog(null, deposit);
} else if (k.isEmpty() == false) {
JOptionPane.showMessageDialog(null, "Deposit field cannot be left blank", "Null Value", 2, null);
} else {
String o = ("Deposit Field is left blank");
JOptionPane.showMessageDialog(null, o);


I agree. Here's the link:
subject: Expected result not coming in an application
It's not a secret anymore!