Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 17th, 2004, 12:42 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , India.
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
Reply With Quote
  #2 (permalink)  
Old August 17th, 2004, 12:59 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , India.
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......");

       }
}



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.