help in insert code

help in insert code

I have some doubt in following code. I want to insert value using prepared statement.we r accessing connection from other package.can u plz help me out.

View Answers

April 8, 2008 at 7:55 PM

hi

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DataInsertServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String firstname=request.getParameter("firstname");
String address=request.getParameter("address");
String email=request.getParameter("email");
String contect=request.getParameter("contect");
// int val = st.executeUpdate("insert regiform values('"+firstname+"','"+address+"','"+email+"','"+contect+"')");
String sql = "INSERT regiform VALUES(?,?,?,?)";
PreparedStatement prest = con.prepareStatement(sql);
prest.setString(1,"vinod");
prest.setString(2,"rohini,sec-2,delhi-85");
prest.setString(3,"[email protected]");
prest.setString(4,"9810254542");
int row = prest.executeUpdate();
con.close();
out.println("Successfully insert data in database");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

}
}









Related Tutorials/Questions & Answers:
help in insert code - JSP-Servlet
help in insert code  I have some doubt in following code. I want to insert value using prepared statement.we r accessing connection from other package.can u plz help me out.  hiimport java.io.*;import java.sql.*;import
insert code jsp to access
insert code jsp to access   insert code jsp to access
Advertisements
code for insert button
code for insert button    i want code for insert button(in image...;The given code uses Swing components to create a image button and allow the user..."); PreparedStatement pstmt = conn.prepareStatement("insert into data(name
help with JDateChooser to insert date into sql
help with JDateChooser to insert date into sql  TextField3 = new com.toedter.calendar.JDateChooser(); TextField3.setDateFormatString("MM-d-yâ...?¦ Statement stmt=con.createStatement(); stmt.executeUpdate("insert into special
insert code using spring - Spring
insert code using spring  Hi, Can any one send code for inserting the data in database using spring and hibernate .. Many thanks, Raghavendra  Hi Friend, Please visit the following link: http
Help in completing Servlet code!
Help in completing Servlet code!  Complete the following Servlet codes to store the information read from the input form to session object. public... String comment = req.getParameter(?commentText?); //Complete the code to store
help to write java code
help to write java code  write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
help to write java code
help to write java code  write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
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
Calender code ! HELP!!!
Calender code ! HELP!!!  how can i add 3 days to current date ? i am.... i am working on a school project & i really need help on this!!!ADS_TO_REPLACE_1 Please help me. This is my code: var Calendar = Class.create();ADS
Java Programming Code HELP
Java Programming Code HELP  Hi, sir/madam. I am new here...: String, attribute name = variable name) Below are my source code. Hope the expert can help me to solve this problem and pull out the attribute name. Can sir
Code Help Needed
Code Help Needed  I am trying to help a buddy of mine with this program and I can't seem to figure it out. I am still working on it but any help...[test]); line. Again thank you for any help. import java.util.*; import
Please help with this code
Please help with this code  I need some help getting the Search method below to work with the menu, and I also cannot figure out how to get my bubble sort to work. I've spent a long time on this and think my brain is just fried
more code help
more code help  Instructions: Write a program to translate a message from English to Morse code. Using a simple text editor like Windows Notepad, create a text file with all of the Morse code combinations for the letters
Java code help
Java code help  Write a java program that will ask the user to input any number from 5 to 9 and then print the following structure depending on the user input. E.g. If the user input is 5, then print the following structure 1 2 3
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve... db. cn u plz tel me the code in detail.n i thk it shud b written in jdbc.....i ve written sum code,bt gting so many doubts in that....so plzzzz help
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi, i have created... plz tel me the code in detail.n i thk it shud b written in jdbc.....i ve written sum code,bt gting so many doubts in that....so plzzzz help me by giving some
need someone to do/help with code
need someone to do/help with code  i need someone to do a code for me. It is a restaurant menu that displays a list of 10 food items. A customer..., along with the number of items sold..please help did a code 500 times cant
Code to insert date in to database - Development process
Code to insert date in to database  Hi , in my following code i want... getting error . plz send me code Error 500--Internal Server Error...:170)   Hi Friend, Try the following code: Thanks
java code to insert select at run time....????
java code to insert select at run time....????  java database code to retrieve data at runtime and please give codes for insert delete too.... using jsp and withot jsp   1)application.jsp: <%@ page import="java.sql.
could anyone please help with the code.
could anyone please help with the code.  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException...(request, response); } } could anyone please check the code. If i enter
ajax code please help to solve this........
ajax code please help to solve this.  in this i am trying to get data...;<a href="help.jsp">help instruction</a></li> <... null; } please help me when i am running this it show an error
Plz help me in writing the code - Java Beginners
Plz help me in writing the code   Write a two user Chess Game. (users must be on different systems
Plz help me in writing the code - Java Beginners
Plz help me in writing the code   Write a two user Chess Game. (users must be on different systems
Hibernate Insert
This tutorial will help you to learn how to insert data into table by using hibernate
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
PLZ HELP ME. i need php code.
PLZ HELP ME. i need php code.   I want php code for bellow OUTPUT. output is just example but it must be letters only. abc bcd efg jku rgt azs hje qqc wws adt
Not sure whats wrong with my code HELP PLEASE?!?!
Not sure whats wrong with my code HELP PLEASE?!?!  I cant figure out what I am doing wrong in my code can anyone help me out??? Grades ADS_TO_REPLACE_1 function computeGrade( ) { var hw, lab, midt, fin, avg; hw
Help on this java code for online library search
Help on this java code for online library search   I have written the following java code for simple library book search. but its having some errors ... please help me on this code. import java.sql.*; import java.awt.
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
Please help me fix this code - MobileApplications
Please help me fix this code   Please help me in this area of code... in the background of the forms in this code i want to sum all expenses amount...); //*********************************************This code section is for List All Trip Expenses Screen
Please help me to modify my java code from php code
]; } } I tried like this (see below JSP code) ... but this is not giving me the exact result as the above PHP code is giving. So please help me to convert...Modify Java code from PHP Code  i want to covert this php code int
insert
insert  insert data in database from servlet through JDBC   Ho Friend, Please visit the following:ADS_TO_REPLACE_1 Insert data into database Thanks
Can anybody help me with this simple MySql code
Can anybody help me with this simple MySql code  select c.countryid, r.bp, r.sp, c.country, t.timee from rate as r, countryloc as c, todaysrate as t... cad 2013-03-16 18:26:31 can any one help me with the query because i want
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case * ** *** ****   Hi friend
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
Insert a row in 'Mysql' table using JSP Code
Insert a row in 'Mysql' table using JSP Code In this section, we will discuss about how to insert data in Mysql database using JSP code. Query... between your Tomcat server & Mysql database Table. Code to insert row in Mysql
need help to remove and optimise the code for creating a page
need help to remove and optimise the code for creating a page   i have the following code but it has some sorts of error whenever i run the page after validation through javascript it calls for the servlets and then i tried
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file: Alan Turing
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert this php code int java/JSP . if (isset($_POST['orders'])) { $orders...]); $array[] = $item[1]; } } I tried like this (see below JSP code
CAN U HELP ME TO CODE IN JSP FOR ONLINE VOTING SYSTEM
CAN U HELP ME TO CODE IN JSP FOR ONLINE VOTING SYSTEM  can u help me to code in jsp for online voting system
please let me get code how to insert a data to mysql using setter and getter method by using java
please let me get code how to insert a data to mysql using setter and getter method by using java  please let me get code how to insert a data... in pure generic way ..all getter and setter in one class , code to insert to db
please let me get code how to insert a data to mysql using setter and getter method by using java
please let me get code how to insert a data to mysql using setter and getter method by using java  please let me get code how to insert a data... in pure generic way ..all getter and setter in one class , code to insert to db
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  1) Copy one file content to other? 2) Count the number of words in a file
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  Q 1) In a class first day 25 students are joined. After two days that total students will increased to 60. We can develop a program by using ArrayList concept
Please help me to write a code for add contacts to groups in a website?
Please help me to write a code for add contacts to groups in a website?   Iam developing a site. In that site I need to write code for Groups... send a code for this? Please make it fast
very urgent : Iam unable to code this program plz help me - RMI
very urgent : Iam unable to code this program plz help me  Write a Multi-user chat server and client.  Hi friend, Chat server is a standlone application that is made up the combination of two-application, server
Pleae help me to give logic and code for this program - Java Beginners
Pleae help me to give logic and code for this program  Write a function that given the string ?original? create a new string ?dramatic? that has two consecutive copies of each letter from the original string. For example

Ads