Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2004, 12:42 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default JSP form values to Oracle table (Insert)

DEAR GOKUL

now i'm in coimbatore, i tried your coding, but it was not working. please give the full coding and with one example.

pls revert back

abbas

Gokul E <gokul_blr@hotmail.com> wrote:
Hi,

Thank you, Where r u from,
Pls try with the followin commands, may be helpful

to get the value entered in the text box value
request.getParameter("NAME") && "NAME" name for the text box defined in
the

|||ly to send back to HTML page
response.setParameter("NAME") && "NAME" name for the text box defined in
the

More details I will send u further on reply,

Gokul

>From: Mohamed Abbas
>To: gokul_blr@hotmail.com
>Subject: please help
>Date: Fri, 13 Aug 2004 04:16:11 -0700 (PDT)
>
>dear gokul
>
>i want one help from u, i was created one servlet and it was connected with
>database, what i want to u, i was created html page in that servlet. i
>going to take the value from html textbox and i use this text to database.
>but it was getting from the html.
>
>String str;
> out.println(" ");
>
> try
> {
> stmt.executeUpdate("insert into login values('"+str+"','testing')");
> }catch(Exception e){System.out.println("insert =>"+e);}
>
>
>reply soon
>
>regards
>
>abbas
>
>


__________________
Gokulan E
 
Old August 17th, 2004, 12:59 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

public class CustomerBean implements Serializable {

    int custId;
    String custName;
    String custCity;

    // Construction to get the instance of the CustomerBean Classs
    public CustomerBean(){
    }

    // get & set method for the CustId
    public int getCustId(){
        return this.custId;
    }
    public void setCustId(int cId){
        this.custId = cId;
    }

    // get & set method for the CustName
    public String getCustName(){
        return this.custName;
    }
    public void setCustName(String cName){
        this.custName = cName;
    }

    // get & set method for the CustCity
    public String getCustCity(){
        return this.custCity;
    }
    public void setCustCity(String cCity){
        this.custCity = cCity;
    }
}

public class CustomerDao {

    public static Connection getOracleConnection() throws SQLException{
        Connection oraConn;

        try{
            Class.forName("oracle.jdbc.driver.OracleDriver");
            oraConn = DriverManager.getConnection("url","username","pwd ");
            return oraConn;
        }catch (ClassNotFoundException ex){
            System.out.println("ClassNotFound " + ex.getMessage());
        }catch(SQLException ex){
            System.out.println("SQL Exception " + ex.getMessage());
        }
        return null;
    }
    public boolean CustomerInsert(CustomerBean customerBean){
        Connection conn;
        Statement stmnt;
        PreparedStatement pStmnt;
        ResultSet rst;

        String insStr = "Insert into G_Customer values(?, ?, ?)";


        try{

            conn = getOracleConnection();
            if (conn == null)
            {
                System.out.println("Conneciton problem");
            }
            else
            {
                System.out.println("SQL is : " + insStr);
            }
            pStmnt = conn.prepareStatement(insStr);
            pStmnt.setInt(1,customerBean.getCustId());
            pStmnt.setString(2,customerBean.getCustName());
            pStmnt.setString(3,customerBean.getCustCity());

// rst = pStmnt.executeQuery(insStr);

            if( pStmnt.executeUpdate() == 1)
            {
                System.out.println(" Message from Here !!! Record Inserted Successfully");
                return true;
            }
            else
            {
                System.out.println("returning false");
                return false;
            }
        }catch(SQLException ex){
            System.out.println("Customer Record updation error " + ex.getMessage());
            return false;
        }
    }
}

// Do Post in the Servlet will call the insert method
    public void doPost(
        HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {

        CustomerBean custBean = new CustomerBean();
        CustomerDao custDao = new CustomerDao();

    // System.out.println("Here we go .... for insert ");

// CustId, CustName, CustCity etc., is the text box name in the JSP

        custBean.setCustId(Integer.parseInt(request.getPar ameter("CustId")));
        custBean.setCustName(request.getParameter("CustNam e"));
        custBean.setCustCity(request.getParameter("CustCit y"));

        if (custDao.CustomerInsert(custBean)) {
           System.out.println("..Insertion is successful......");

       }
}








Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP code to insert values from HTML form to SQL se rbyamukama Pro JSP 3 January 29th, 2013 07:42 AM
insert multiple records into a table from values Deepak Chauhan Oracle 3 May 12th, 2006 10:35 PM
How to pass vector values form one JSP midhun JSP Basics 1 January 30th, 2006 06:49 PM
Insert ODBC Values into Table Ben Access VBA 3 January 26th, 2005 01:12 PM
Access update table from form values trevander Access VBA 2 April 28th, 2004 03:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.