0

I am using the netbeans and mysql. I have a table named employee with the following fields" emp_id, emp_name, intime, date. I try to retrieve a particular record using this query:

SELECT intime FROM employee WHERE emp_id='1' AND date='25/06/12'

I get an error saying empty resultset, but the table contains that particular record. Why did this error occurred?

error: dsdcom.mysql.jdbc.JDBC4ResultSet@d20b73
6
  • 2
    please provide some code on how do you connect to db, how you execute the command etc ... Commented Jun 26, 2012 at 6:13
  • ... and probably the table structure and a data row Commented Jun 26, 2012 at 6:18
  • run above query directly in mysql using HeidiSQL or something like that. And make sure that it returns the result you want. By using this method you can correct errors in your query. If query returns correct result, then provide your connection related code to check for errors Commented Jun 26, 2012 at 6:25
  • it returns 0 rows but table contains a record of such type Commented Jun 26, 2012 at 6:43
  • Class.forName("com.mysql.jdbc.Driver"); DriverManager.getConnection("jdbc:mysql://localhost:3306/attendance", "root", "karma"); Commented Jun 26, 2012 at 6:45

4 Answers 4

1

Try to write/execute query using PreparedStatement,

String sql="Select intime from employee where emp_id=? and date=?";
PreparedStatement statement=conn.prepareStatement(sql);
statement.setInt(1,1);
statement.setDate(2,java.sql.Date.valueOf("2012-06-25"));
ResultSet rs=statement.executeQuery();
if(rs.next())
 {
   //found
 }
Sign up to request clarification or add additional context in comments.

Comments

0

maby date field is keywords or database table data field some column is null,i suggest you double checked.

Comments

0

run above query directly in mysql using HeidiSQL or something like that. And make sure that it returns the result you want. By using this method you can correct errors in your query.

14 Comments

I run this query but it retuns 0 rows
you mean you run query directly in MySql right? Then there should be some problem in your query. Error may be in "date='25/06/12'" part of the query.
please execute "SELECT intime FROM employee WHERE emp_id='1'" and tell me result
I am taking the date value from the Textbox..and match that value to tables contents..and retrived the record from table.and datatype of date field in table is text..so what is problem..i cant guess
I tried this it giving error:MySQL returned an empty result set
|
0

Try something like

SELECT intime FROM employee WHERE emp_id='1' AND date like '25/06/12'

1 Comment

I have tried this but it gives error :MySQL returned an empty result set (i.e. zero rows).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.