Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 16th, 2013, 04:31 AM
bobby131276 bobby131276 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 bobby131276 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 10 sec
Reputation Power: 0
PreparedStatement using two clauses return empty set

Hi, all. I have login table
DROP TABLE IF EXISTS login;
CREATE TABLE login (
id BIGINT AUTO_INCREMENT,
username VARCHAR(20),
password VARCHAR(100),
PRIMARY KEY(id)
);
LOAD DATA LOCAL INFILE 'login.txt' INTO TABLE login;


I want to make a query in Java to match username and password. One of the row value is username='untirta', and password='untirta'.

Code:
try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = null;
            try {
                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ti", uname, pword);
                String npm = "untirta";
                String passwd = "untirta";

                String query = "SELECT * from login WHERE username=? AND password=?";
                PreparedStatement stmt = con.prepareStatement(query);
                stmt.setString(1, npm);
                stmt.setString(2, passwd);
                //Statement stmt = con.createStatement();
                ResultSet rs = stmt.executeQuery();

                while (rs.next()) {
                    int id = rs.getInt(1);
                    String name = rs.getString("username");
                    String password = rs.getString("password");
                    System.out.println(name);
                    System.out.println(password);
                }
            } catch (SQLException ex) {
                Logger.getLogger(Tes.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    if (!con.isClosed()) {
                        con.close();
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(Tes.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Tes.class.getName()).log(Level.SEVERE, null, ex);
        }


The resultset return null (no value). I also try in mysql command utility and return empty set. Are there something wrong in my code? I developed the code in Neatbeans 7.2.1. and MySQL 5.5.28. Thank you anyone for the time.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > PreparedStatement using two clauses return empty set

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap