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
Related Tutorials/Questions & Answers:
Advertisements
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 fieldfetch 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 fieldfetch 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 tableretrieve
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 databasestore 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 - StrutsTo
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 DatabaseGWT --
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 & retrivehow 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
store and retrive image from database - JDBCstore 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
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
Write records into text file from databaseWrite 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
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
url parameter using retrive data from database in jspurl 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
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 jspurl 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
Insert text file data into DatabaseInsert 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 databaseInsert 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 - SQLinsert 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 ?
..........................
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 tableretrieve
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
add record to database - JDBCadd
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