[nbj2ee] Search on Derby Database not executed.

  • From: "yashshah" < >
  • To:
  • Subject: [nbj2ee] Search on Derby Database not executed.
  • Date: Wed, 05 Dec 2012 09:01:26 -0500

I have written this code to perform a search function on my Derby Database. 
However I don't know what is wrong because the function won't execute and can 
I redirect the page to my result.xhtml on execution of search(). Please help. 
Here are my codes.


> patientsearch.java


Code:

package CMS;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name="patientsearch")
@RequestScoped
public class patientsearch{

    public patientsearch() {
    }
    
    private int id;
    private String name;
    private int id1;
    private String name1;
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    
    public Integer getId1() {
        return id1;
    }

    public void setId1(Integer id1) {
        this.id1 = id1;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public String getName1() {
        return name1;
    }

    public void setName1(String name1) {
        this.name1 = name1;
    }
    
    public String search()
    {
        try
        {
            String host = "jdbc:derby://localhost:1527/CMS";
            String username = "yash";
            String password= "yash";
            Connection con = DriverManager.getConnection( host, username, 
password );
            PreparedStatement stmt= con.prepareStatement("SELECT id,fname 
FROM patient where id=?");
            stmt.setInt(1,id);
            ResultSet rs = stmt.executeQuery();
            while(rs.next( ))
            {
            id1 = rs.getInt("id");
            name1 = rs.getString("fname");
            }
        }
        catch ( SQLException err )
        {
            System.out.println( err.getMessage( ) );
        }
        return null;
    }
}





> search.xhtml


Code:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml";
      xmlns:h="http://java.sun.com/jsf/html";>
    <head>
        <title>Patient Search</title>
    </head>
    <body>
        <h:form>
            <h:inputText value="#{patientsearch.id}" />
            <h:commandButton value="Submit" action="#{patientsearch.search}"/>
        </h:form>
        </body>
</html>





> result.xhtml


Code:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml";
      xmlns:h="http://java.sun.com/jsf/html";>
    <head>
        <title>Patient Result</title>
    </head>
    <body>
        <h:form>
            <h:panelGrid columns="2">
                <h:outputText value="#{bundle.ViewPatientLabel_id}"/>
                <h:outputText value="#{patientsearch.id1}" title="ID"/>
                <h:outputText value="#{bundle.ViewPatientLabel_fname}"/>
                <h:outputText value="#{patientsearch.name1}" title="Name"/>
            </h:panelGrid>
        </h:form>
    </body>
</html>









[nbj2ee] Search on Derby Database not executed.

yashshah 12/05/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close