retrive record from the text field and insert into to database

retrive record from the text field and insert into to database

the following code is inserting values in the my sql database but i want to insert the data into oracle database , i want what changes i have to make in the following code...

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").toString();
        String FIRSTNAME = request.getParameter("FIRSTNAME").toString();
        String ADDRESS = request.getParameter("ADDRESS").toString();
        String CITY = request.getParameter("CITY").toString();

    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 set LASTNAME='"+LASTNAME+"',FIRSTNAME='"+FIRSTNAME+"',ADDRESS='"+ADDRESS+"',CITY='"+CITY+"'";


            int i = st1.executeUpdate(query);

            if(i>0)
            {
                response.sendRedirect("SHome");
            }
             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);   
        }   
    }

} } when i run this code i am getting followinng error "ORA-00926: missing VALUES keyword "

View Answers

March 26, 2012 at 3:30 PM

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.sql.*;
class Form extends JFrame
{
JButton ADD;
JPanel panel;
JLabel label1,label2,label3,label4,label5;
final JTextField text1,text2,text3,text4,text5;
Form(){
label1 = new JLabel();
label1.setText("UserID:");
text1 = new JTextField(20);

label2 = new JLabel();
label2.setText("First Name:");
text2 = new JTextField(20);

label3 = new JLabel();
label3.setText("Last Name:");
text3 = new JTextField(20);

label4 = new JLabel();
label4.setText("ADDRESS:");
text4 = new JTextField(20);

label5 = new JLabel();
label5.setText("Email:");
text5 = new JTextField(20);

ADD=new JButton("ADD");

panel=new JPanel(new GridLayout(6,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(text4);
panel.add(label5);
panel.add(text5);
panel.add(ADD);
add(panel,BorderLayout.CENTER);
setTitle("FORM");
ADD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
String value3=text3.getText();
String value4=text4.getText();
String value5=text5.getText();
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();

             st.executeUpdate("insert into data(id,fname,lname,address,email) values('"+value1+"','"+value2+"','"+value3+"','"+value4+"','"+value5+"')");
            JOptionPane.showMessageDialog(null,"Inserted Successfully!");
        }
catch(Exception e){}
}
});
}
}
class FormDemo
{
public static void main(String arg[])
{
try
{
Form frame=new Form();
frame.setSize(300,300);
frame.setVisible(true);
}
catch(Exception e)
{
}
}
}

March 26, 2012 at 3:52 PM

Thanx...









Related Tutorials/Questions & Answers:
retrive record from the text field and insert into to database
retrive record from the text field and insert into to database  the following code is inserting values in the my sql database but i want to insert the data into oracle database , i want what changes i have to make
Fetched Record from database show into text field of html page
Fetched Record from database show into text field of html page  hi, i have a database with field merchant_code, merchant_name, city, region, and also have html page with all above mentioned field i have submit 20 record from
Advertisements
How to retrive a particular record from database in php with mysql?
How to retrive a particular record from database in php with mysql?  Am using phpMyAdmin Database.In mysql database having 10 records. The field... record based on username and password. I dont know how to retrive in php with mysql
insert and retrive image from sql server database in jsp
insert and retrive image from sql server database in jsp  what is the code to insert and retrive an image from sql server database in jsp
Retrive data from databse to a text field - Java Server Faces Questions
Retrive data from databse to a text field  Hi, Can you give me a source code to rertrve data from Mysql databse to a text field using JSF.....by selecting option from a dropdown option
retrive data from database?
retrive data from database?  hellow i have a database sheet name... from db1 and enter value in text box according there name,rollno and save..... now i want retrive sn,roll no and name and textbox like
retrive data from database
retrive data from database   hi.. i made a application form. it's have attribute s.no,name,roll no and i enter a few records. now i want to view all record not in database access sheet i want to view it at any another
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table as if i am... "rs.getString" in the text field also..   import java.awt.*; import
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table wth edit...;/td>"); the i am getting "rs.getString" in the text field also..  
Acess Record from database.
Acess Record from database.  How to access records from database and how to display it on view page, with the help of hibernate
retrieve record from the field table
retrieve record from the field table  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from the field table
store and retrive image from the database
store and retrive image from the database  please provide me... to store and retreive images from sql database using sql commands -how to store and retreive images from sql database using asp.net/c# thanks in advance
To retrive data from database - Struts
To retrive data from database  How to get values ,when i select a select box in jsp and has to get values in textbox automatically from database? eg... come to jsp page automatically from database
GWT -- retrive the data from Database
GWT -- retrive the data from Database  the user can create an event. In the create page, we have three buttons. Save as draft, preview and save... button, you have to create a dynamic jsp which should read the contents from
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
Can i insert image into struts text field
Can i insert image into struts text field  please tell me can i insert image into text field
store & retrive the image from oracle database
store & retrive the image from oracle database  how can i store the image path in tha database & fetch that image from oracle database
store and retrive image from database - JDBC
store and retrive image from database  how to store and retrive an image in database using java?  Hi friend, Code for store image...()); } } } For retrieve image from database visit to : http
automatically move next page when data fetched from database is stored in text field
automatically move next page when data fetched from database is stored in text... are stored in database wherein when the in the first text field the data is already... from database and entered the next page should load without the user clicking
retrive image from database using jsp without stream
retrive image from database using jsp without stream  How to retrive image from database using jsp without stream like (inputStream
Question about "Insert text file data into Database"
Question about "Insert text file data into Database"  Hey I was reading the tutorial "Insert text file data into Database", (awesome btw), and noticed that both a FileInputStream, a DataInputStream and a BufferedReader
insert rows from browsed file to sql database
, content of the file has to go to database. how can i insert record into database...insert rows from browsed file to sql database  i need to insert rows from excel to database by browsing the file in jsp. by connecting both
retrive data from database using jsp in struts?
retrive data from database using jsp in struts?   *search.jsp* <%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <... searchProduct(SearchDTO sdto) { String query="select * from product
insert values from excel file into database
the following link: Insert values from excel file to database...insert values from excel file into database   hi i want to insert values from Excel file into database.Whatever field and contents are there in excel
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
How To Insert A New Record to MS Access table database in GUI
How To Insert A New Record to MS Access table database in GUI  Hello... that involves inserting a record into a 6-column table in my MS Access database table. I'm..._UPDATABLE); String sql = "select * from DonorTable"; rs
Write records into text file from database
Write records into text file from database You have already learnt how to insert records from text file to database. But here we are going to retrieve records from database and store the data into the text file. For this purpose, we have
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
By dropdownlist retrive data from database and show in textbox in jsp.
By dropdownlist retrive data from database and show in textbox in jsp.  Hello Sir, I am doing project in jsp.I have to retrive data from database, when I select value from dropdownlist, and that data I want to show in textbox
retrive the data from access database to drop down list box in jsp
retrive the data from access database to drop down list box in jsp  hai, im new to jsp now im using the jsp along with access database.in table i load all the data's i need to retrive the data from database to dropdown list box
JDBC Insert Record
JDBC Insert Record      .... In JDBC,Statement object perform an insert record using  batch updates... is processed. Finally the execute Query ( ) return you the record set from a table
Loading a jsp page (with record from database) from another jsp page
Loading a jsp page (with record from database) from another jsp page  ... with records from database(against Serial no and year).That is, as soon as Getdata.jsp will be loaded, it will show the first record. How can I do
How to retrive an inmage from database and displaying it in imgae box - Swing AWT
How to retrive an inmage from database and displaying it in imgae box ...? I want to retrive an image from database and to display it in a small imagebox...(); f.setTitle("Display Image From database"); Image image = f.getToolkit
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp   the user can create an event. In the create page, we have three buttons. Save as draft... the contents from the db based on the event id. But this jsp url should be a public
jsp code for a drop down box to retrive value from database
jsp code for a drop down box to retrive value from database  my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q   1)login.jsp: <html> <script>
fetch record from oracle database using jsp-servlet?
fetch record from oracle database using jsp-servlet?  how can i fetch data from oracle database by using jsp-servlet. i'm using eclipse, tomcat server and oracle database and creating jsp pages and also using servlet
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp  The user can create an event. In the create page, we have three buttons. Save as draft... the contents from the db based on the event id. But this jsp url should be a public url
Retrive only requird data from a table in MYSQL databade to JSP file..on a field submit button.
Retrive only requird data from a table in MYSQL databade to JSP file..on a field submit button.  i have MYSQL DB,DB NAME:TRLIST, TABLE NAME:TR_LIST... from table TR_LIST on typing TR values in an input-text-box and by clicking<
how to retrive the particular data from database in php with mysql?
how to retrive the particular data from database in php with mysql?  when am using mysqlfetcharray() that display the following error. the code look..._db("samp", $con); $Name=$_POST['unames']; $data=mysql_query("SELECT * FROM tbl
Using C# DataGridView to insert record into Microsoft SQL Server 2005 database - SQL
Using C# DataGridView to insert record into Microsoft SQL Server 2005... creating a sales database system using C# and Microsoft SQL Server 2005. I had encounter a problem of using C# DataGridView to insert record into Microsoft
Insert text file data into Database
Insert text file data into Database In this section, you will learn how to insert the text file data into the database. For this purpose, we have created... is then inserted into the database. Here is the student.txt: 1 
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database... description The server encountered an internal error () that prevented it from
Fetching database field from servlet to jsp page ?
Fetching database field from servlet to jsp page ?  Hello Java... field. I wanted to pass some of the database field from servlet to jsp... (i am opening my database in servlet init() method ) how to pass rs.getString(8
insert and retrive data and time - SQL
insert and retrive data and time  hello everybody . Is there any method in java so that we can insert current system time and then it can be retrieve that date and time from database ? ..........................  
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
image retrive into DataBase - JDBC
, Retrieving image from database is easy task. JDBC provides all the necessary API and function to retrieve the image from database. You retrieve image from database... shows you how to retrieve image from database using a servlet and then show
retrieve record from table
retrieve record from table  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from the field table. Actually
insert rows from Excel sheet into a database by browsing the file
insert rows from Excel sheet into a database by browsing the file  hello, I am trying to insert rows from Excel sheet into SQL database by browsing... and then on submission of form value should get insert into a database. please provide me
add record to database - JDBC
add record to database  How to create program in java that can save record in database ?  Hi friend, import java.io.*; import java.sql....{ response.setContentType("text/html"); PrintWriter out = response.getWriter
PHP SQL Insert
; PHP SQL Insert is used to insert the record from HTML page to Mysql ... illustrate an example from PHP SQL Insert . To understand the example, firstly...;. The insert.php is connected to the database and submit the records from HTML page

Ads