Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet getting error while inserting values in database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


megha singhal
getting error while inserting values in database
1 Answer(s)      2 years and 9 months ago
Posted in : JSP-Servlet


AddUser.java

import java.io.*;   
import java.sql.*;   
import javax.servlet.*;   
import javax.servlet.http.*;   
import java.util.*;   
import java.lang.String;   
import java.sql.Connection;
import javax.servlet.RequestDispatcher;

import java.sql.Statement;   
import java.sql.ResultSet;   
import javax.naming.*;   
import javax.naming.directory.*;   
import oracle.jdbc.pool.OracleDataSource;  

public class AddUser extends HttpServlet{ 

   public void doPost(HttpServletRequest request, HttpServletResponse response)
                                   throws ServletException,IOException{
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();



            String LASTNAME = request.getParameter("LASTNAME");
            String FIRSTNAME = request.getParameter("FIRSTNAME");
            String ADDRESS = request.getParameter("ADDRESS");
            String CITY = request.getParameter("CITY");

        Connection con = null;   
                Statement st1 = null;   

                ResultSet rs = null;   

         try {   

                 Context initContext = new InitialContext();                     
                 Context envContext = (Context) initContext.lookup("java:/comp/env");                     
                OracleDataSource ds = (OracleDataSource) envContext.lookup("jdbc/abc");                      
                 if (envContext == null)throw new Exception("Error: No Context");                   
                if (ds == null) throw new Exception("Error: No DataSource");                    
                if (ds != null)                           
                 con = ds.getConnection();   

                st1 = con.createStatement();   




                ArrayList al=null;
                ArrayList userList =new ArrayList();
                String query = "insert into LTCINFO.PERSONS values ('"+LASTNAME+"','"+FIRSTNAME+"','"+ADDRESS+"','"+CITY+"')";


                int i = st1.executeUpdate(query);

                if(i>0)
                {
                    response.sendRedirect("SRord");
                }
                 rs.close();   
                    st1.close(); 
                 con.close();   

        } catch (SQLException se) {   
            out.println("An Error Had occurred while accessing the database");   
            out.println("<HR>");   

            out.println(se.getMessage());   
        }   

        catch (Exception e) {   
            e.printStackTrace();   

        } finally {   
            try {   
                if (rs != null)   
                    rs.close();   
                if (st1 != null)   
                    st1.close();  

                if (con != null)   
                    con.close();   
            } catch (Exception e) {   
                out.println(e);   
            }   
        }   




  }
}                                                                                                                                                                                   addUser.jsp

 <html>
<head>
</head>
<body>
<form name="userform" method="post" action="AddUser">
<br><br><br>
<table align="center" width="300px" style="background-color:#EDF6EA;border:1px solid #000000;">
<tr><td colspan=2 style="font-weight:bold;" align="center">Add User</td></tr>
<tr><td colspan=2 align="center" height="10px"></td></tr>
    <tr>
        <td style="font-weight:bold;">LASTNAME</td>
        <td><input type="text" name="LASTNAME" value=""></td>
    </tr>
    <tr>
        <td style="font-weight:bold;">FIRSTNAME</td>
        <td><input type="text" name="FIRSTNAME" value=""></td>
    </tr>



    <tr>
        <td style="font-weight:bold;">ADDRESS</td>
        <td><input type="text"  name="ADDRESS" rows=5 cols=25></td>
    </tr>
    <tr>
        <td style="font-weight:bold;">CITY</td>
        <td><input type="text" name="CITY" value=""></td>
    </tr>


    <tr>
        <td></td>
        <td><input type="submit" name="Submit" value="Save" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
    </tr>
    <tr><td colspan=2 align="center" height="10px"></td></tr>
</table>
</form>


</body>
</html>

for the above i m facing followin error i don't know why "ORA-00947: not enough values". kindly chk this...


Advertisement
View Answers

Related Tutorials/Questions & Answers:
getting error while inserting values in database
getting error while inserting values in database  AddUser.java...) { out.println("An Error Had occurred while accessing the database... followin error i don't know why "ORA-00947: not enough values". kindly chk
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
Advertisements
Lock while inserting/updating database in multithreaded.
Lock while inserting/updating database in multithreaded.  Hi, I am... inserting/updating to database. I dont know what is the issue but it was never... of each transaction and rollback at the time of error. After each transaction I give
error while inserting millions of records - EJB
error while inserting millions of records  Hello, I am using ejb cmp and inserting 1 millions of records but it won't work because trancation time... e.printStackTrace(); } }   The following error is occur
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  http://www.roseindia.net/answers/viewqa/Ajax/15250-DropDown-in-ajax+jsp.html... to insert all selected values in data base correspondent to each like if user
Im getting this error while running JPA project
Im getting this error while running JPA project  Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: examplePersistenceUnit] Unable to configure EntityManagerFactory
getting values from database - JSP-Servlet
getting values from database  I tried the following code abc.html aaa.jsp I am not getting exceptions now... JSP code separately.If it will not display database values then try your code
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has... it in the code. but still i am getting the error in the update query. please provide
Inserting values in MySQL database table
Inserting values in MySQL database table   ... the facility for inserting the values in MySQL database table. Description... to insert the values in the database. Here we are going to see, how we can
Getting Error - Development process
Getting Error   Hi , i am getting error while executing this code. I just want to store date in to database. Dont mistake me for repeated questions... of query values and destination fields are not the same. my table : Add_Data
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
Getting an error :(
Getting an error :(  I implemented the same code as above.. But getting this error in console... Console Oct 5, 2012 10:18:14 AM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server
inserting all the values in a html table column
inserting all the values in a html table column  strong text hai everyone, i'm a fresher to servlet i need to know that, how can i insert all the values in a html table column into a database. Thanks in advance
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration through for loop but it is not getting inserted ..it is taking only one value
Exception while inserting image in oracle using java
Exception while inserting image in oracle using java  import java.sql.*; import java.io.*; class Oracle2 { public static void main(String args[])throws Exception { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver
inserting multiple file formats into database
inserting multiple file formats into database  hi i want to insert multiple file format like .pdf.doc.zip into mysql database using jsp
Getting image pixel values
Getting image pixel values  how to get image pixels values on mouse click   import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.*; import javax.swing.*; public class
inserting an path of an image in database - JDBC
be saved in the database...I have tried it but getting an error.. plz have a look...inserting an path of an image in database  hello kindly help related... time its full path should be inserted in the database(MS Sql 2000).. I m able
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from the database) My question is when i select a particular value it should be pass
Inserting id in place of name to database
Inserting id in place of name to database  Hello, I have a database department where I have "id" and "name". I am fetching this data to a jsp form in dropdown list displaying "name" there and Now I wanted to insert data from
Getting error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.
Getting error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.  I am doing project in JSP with database WampServer and glassfish as server .when i done database connection then i get an error
Records are not inserting in to main table while running the mysql stored procedure.
Records are not inserting in to main table while running the mysql stored... that procedure records are not inserted into main table from temp table.But im getting msg... me with this issue. My Code: BEGIN select concat('Inserting into SD
getting classnotfound exception while running login application
getting classnotfound exception while running login application  hi, I am getting Error creating bean with name 'urlMapping' defined... to bean 'loginController' while setting bean property 'urlMap' with key
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... and then the result at the end.I need to add simple database connectivity...(this).start(); } public void run() { while(start_test
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... and then the result at the end.I need to add simple database connectivity...(this).start(); } public void run() { while(start_test
error while compiling - Java Beginners
error while compiling  i am facing problem with compiling and running a simple java program, can any one help me, the error i am getting is javac is not recognised as internal or external command  Check if you JAVA_HOME
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following... to a databse by a servlet.I used the example in "Inserting Data In Database table...:8080/DataInsertion/DataInsertion) in the browser, I just saw my designed database in the form
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password  Hi, I need the functionality in JSP to encrypt the password while inserting into DB and need decrypt logic while
inserting multiple file formats into database using html
inserting multiple file formats into database using html   hi the code was working fine,i want to choose the file and then upload to database,by using html.whether it is possible to upload larger file size,please explain
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password
Password need to encrypt while inserting into DB and need to decrypt while responding to forgot password  Hi, i encrypt password and stored in to DB.but i dont know decrypt that password.plz send the code.in your site link
inserting into mysql database with uid to be primary key and autoincrement
; Here is the code of inserting values from jsp form to database...inserting into mysql database with uid to be primary key and autoincrement  hello, i am new to jsp and facing problem in creating a database entry
Advertisements
 

 

 

DMCA.com