2

i have a table - emp_details in mysql i want to seatch an employ's id number in java. if it is in the table , then show all the details of employee. otherwise display an error message. how i do this

2
  • 1
    Another poorly-disguised homework question. Commented Nov 18, 2010 at 8:35
  • @skaffman +1 , ans so my answer Commented Nov 18, 2010 at 8:48

2 Answers 2

2

Using JDBC
Here is an example You can build your solution from it.

   Statement stmt = null;
    String query = "select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from " + dbName + ".COFFEES";
    try {
      stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(query);
      while (rs.next()) {
        String coffeeName = rs.getString("COF_NAME");
        int supplierID = rs.getInt("SUP_ID");
        float price = rs.getFloat("PRICE");
        int sales = rs.getInt("SALES");
        int total = rs.getInt("TOTAL");
        System.out.println(coffeeName + "\t" + supplierID + "\t" + price + "\t" + sales + "\t" + total);
      }
    } catch (SQLException e ) {
      JDBCTutorialUtilities.printSQLException(e);
    } finally {
      stmt.close();
    }
Sign up to request clarification or add additional context in comments.

4 Comments

iam taking values to resultset
then how i compare the values
ResultSet rs1=stmt.executeQuery("SELECT Employee_ID FROM `employee_details ");
if(keyboard value!=) { } else{ }
0
ResultSet rs1=stmt.executeQuery("SELECT * FROM employee_details where Employee_ID='"+strEmpId+"'");

if(rs1.next()) {
 System.out.println("Emp ID : " + rs1.getString(1));
 System.out.println("Emp Name : " + rs1.getString(2));
 System.out.println("Emp Salary : " + rs1.getString(3));
} else {
  System.out.println("Emp ID not found");
}

If you want to know more about SQL just go through HERE

Comments

Your Answer

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