Results 1 to 8 of 8
  1. #1
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Post Problem in inserting value from textbox into datyabase

    Hey can any1 tell me how to insert data from textbox on button click in jsp.

  2. #2
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: Problem in inserting value from textbox into datyabase

    This is myh code...

    <body>
    <form action="sample1.jsp" method="Get">
    <h2>Create User </h2>
    First Name:<input type="text" name="Fname" value="">
    <br/>
    <br/>
    Last Name:<input type="text" name="Lname" value="">
    <br/>
    <br/>
    Address:<textarea id="TextArea1" cols="20" name="S1" rows="2"></textarea>
    <br/>
    <br/>
    City:<input type="text" name="city" value="">
    <br/>
    <br/>
    State:<input type="text" name="state" value="">
    <br/>
    <br/>
    Pin:<input type="text" name="pin" value="">
    <br/>
    <br/>
    EMail:<input type="text" name="email" value="">
    <br/>
    <br/>
    Confirm EMail:<input type="text" name="cmail" value="">
    <br/>
    <br/>
    User Name:<input type="text" name="uname" value="">
    <br/>
    <br/>
    Password:<input type="password" name="password" value="">
    <br/>
    <br/>
    Confirm Password:<input type="password" name="cpassword" value="">
    <br/>
    <br/>
    Security Question:<textarea id="TextArea1" cols="20" name="S1" rows="2" ></textarea>
    <br/><br/><br/>
    <input type="submit" value="Register"/>
    </form>
    <%

    Connection conn=null;
    Statement st=null;
    PreparedStatement pst=null;

    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    } catch (ClassNotFoundException e) {
    out.println("<h1>Driver not found:" + e + e.getMessage() + "</h1>" );
    }

    try {
    String Fname=request.getParameter("Fname");
    String Lname=request.getParameter("Lname");
    String address=request.getParameter("address");
    String city = request.getParameter("city");
    String state=request.getParameter("state");
    String pin=request.getParameter("pin");
    String email=request.getParameter("email");
    String uname=request.getParameter("uname");
    String password=request.getParameter("password");
    String ques=request.getParameter("ques");
    conn = DriverManager.getConnection (
    "jdbc:sqlserver://localhost:1433;databaseName=shopping_potal",
    "sa", "ashu@123" );

    st = conn.createStatement();
    st.executeQuery("insert into register values('" + Fname+ "','" + Lname + "','" + address + "','" + city+ "','" + state + "','" + pin + "','" + email+ "','" + uname + "','" + password + "','" + ques + "')");
    conn.close();
    }
    catch (Exception e) {
    out.println( "<h1>exception: "+e+e.getMessage()+"</h1>" );
    e.printStackTrace();
    }
    %>
    </body>

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Problem in inserting value from textbox into datyabase

    Are you getting any errors?
    If so post them here including stack trace.

    I will say first that you should be using a PreparedStatement rather than concatenating your SQL together, and second that the whole JDBC code should not be done in a JSP page. JSP pages should be used for displaying stuff, not processing requests. Servlets should be used for that.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: Problem in inserting value from textbox into datyabase

    hey pls tell can't we do without using servelet.
    And i am not getting error and i have used prepared statement to but in my database i am getting the null value actuly its not reading the textbox .
    And i don't know how to use servelet .

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Problem in inserting value from textbox into datyabase

    You can use the JSP, but it's not the way it should be done.
    However, I have noticed a lot of people teaching this stuff start with JSPs, which is really not the right way round in my opinion, but never mind.

    So, if you are using a PreparedStatement then you should show that code, so that we know you are using it correctly.

    And also show what is actually getting inserted.
    Which field is null?
    Which is a null value.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: Problem in inserting value from textbox into datyabase

    Thanks sir but i have done it and my problem is solved..

  7. #7
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,990
    Rep Power
    5

    Default Re: Problem in inserting value from textbox into datyabase

    Quote Originally Posted by Ashu View Post
    Thanks sir but i have done it and my problem is solved..
    Good. But please, learn how to use servlets. Here is a free book that explains all:

    Free Online Version of Core Servlets and JavaServer Pages (Second Edition) in PDF
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    Ashu is offline Member
    Join Date
    Jul 2013
    Posts
    16
    Rep Power
    0

    Default Re: Problem in inserting value from textbox into datyabase

    oki... thnku sir... :-)

Similar Threads

  1. problem with inserting into table
    By pardhu in forum AWT / Swing
    Replies: 2
    Last Post: 11-19-2011, 04:46 AM
  2. problem with inserting into table
    By pardhu in forum JDBC
    Replies: 1
    Last Post: 11-19-2011, 04:42 AM
  3. problem with inserting value to nextpage
    By kiki2009 in forum Advanced Java
    Replies: 0
    Last Post: 05-05-2011, 03:46 PM
  4. Problem when inserting in java
    By aleksandar in forum Java Applets
    Replies: 2
    Last Post: 02-08-2011, 01:21 PM
  5. Problem inserting into database
    By Unnel in forum JDBC
    Replies: 13
    Last Post: 01-23-2011, 09:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •