Results 1 to 5 of 5
  1. #1
    mjz
    mjz is offline Member
    Join Date
    Mar 2009
    Posts
    6
    Rep Power
    0

    Default ResultSet next() returns false Yet Tuples Present

    Please help me figure out what could be going on.I am using Oracle thin driver and PreparedStatement.

    Java Code:
      public  boolean aunthenticate1(Connection conn,String username,String password) throws SQLException{   	
            	
            PreparedStatement st2 = null; 
            
        	try{       		
        
        	String uquery = "Select username,password from mjzeko.users where username= ? AND password= ? ";    	
        	st2=conn.prepareStatement(uquery);    
        	st2.setString(1, username);
        	st2.setString(2, password);     	
        	st2.executeQuery();
        	ResultSet res =st2.getResultSet();
        	System.out.println("2222");
        	//boolean t=res.next();    	
        	System.out.print(res.getRow());
        	int count=0;
        	while (res.next()){             
                System.out.print("res.getString(1)"); 
                count++;
                System.out.print(count); 
                  }
        	 if(count > 0) 
        		return true;
        	else { 
        		System.out.print(count); 	
        	       return false;
        	   }
        	  } 	   	
        	
        	catch(Exception ex)
        	{      
                    ex.printStackTrace();    	     
        		System.out.print("This is where I end up");
        		ex.getMessage();
                  ex.getCause();
        		return false;
        	} 
        	finally{
        	      st2.close();  
        	}
        }
    Thanks
    Last edited by Fubarable; 08-08-2009 at 01:36 PM. Reason: code tags added to aid in readability

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    would you mind giving the incorrect output of the program

  3. #3
    mjz
    mjz is offline Member
    Join Date
    Mar 2009
    Posts
    6
    Rep Power
    0

    Default ResultSet next() Returns false Yet Tuples Present -CODE OUTPUT

    mtyoung thanks for the reply.The code outputs

    2222
    00 //first 0=getRow() 0=count
    falsefalse //one from return and the last one from authenticate1()

    Thanks

  4. #4
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    is your database table contains record with username= ? "AND" password= ?

  5. #5
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    No records for your selection.

    Just check the setString method .before setting the string trim the spaces and check whether the setting string exactly matches with database data.
    Ramya:cool:

Similar Threads

  1. Reading a zip/text file present in a MAC Bundle
    By Prasannaa in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2008, 04:05 PM
  2. How to read a .EML file present on Remote Desktop?
    By anil@prokarma in forum New To Java
    Replies: 0
    Last Post: 06-12-2008, 03:05 PM
  3. hibernate lazy=False
    By Ed in forum JDBC
    Replies: 2
    Last Post: 07-02-2007, 08:54 PM
  4. To send email of page present Web from a Jsp
    By Marcus in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-09-2007, 05:08 AM
  5. Replies: 4
    Last Post: 05-19-2007, 12:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •