Java servlet

Java servlet

View Answers

September 3, 2009 at 12:26 PM

Hi Friend,

We are providing you a code that will connect the servlet to database and insert the data.

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

public class ConnectAndInsert extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
int id=5;
String connectionURL = "jdbc:mysql://localhost:3306/register";;
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(connectionURL, "root", "root");
System.out.println("Connect to database");
PreparedStatement ps = con.prepareStatement("INSERT INTO data VALUES(?,?)");
ps.setString(1,"Roseindia");
ps.setString(2,"Delhi");
int i = ps.executeUpdate();
ps.close();
con.close();
System.out.println("Disconnect to database");
}
catch(Exception ex){
System.out.println(ex);
}

}
}

Thanks









Related Tutorials/Questions & Answers:
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
Java servlet
Java servlet  What is servlet
Advertisements
JAVA SERVLET - JSP-Servlet
JAVA SERVLET Log   Hi, A servlet file which create the log files ,then writing values to the list & log, we should have a thousand separator and no decimal values. This means instead of writing 986300.0 in the Log file
Java(Servlet) - Servlet Interview Questions
Java Servlet examples  Java and Servlet programming examples
java servlet - JSP-Servlet
java servlet  hi friends, Thanks in advance. Am poornima am created new servlet in eclipse its open but without including any code am getting..., Put servlet-api.jar into the lib folder of apache tomcat server. Thanks
java servlet
java servlet   im using ubuntu 12.04 and ialready installed eclipse but i dont know how to run the servlet programs please give brief procedure to run the servlet program in eclipse
Java servlet
Java servlet  What is the difference between an applet and a servlet
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
Java Servlet Problem - JSP-Servlet
Java Servlet Problem  I have a servlet class that implemets the ServletContextAttributeListener interface. I am overriding all three methods, but in the attributeReplaced() method, i want to perform a redirect to another servlet
Java Servlet - JSP-Servlet
Java Servlet  3-tier structures of servlets
java servlet programming - JSP-Servlet
java servlet programming  i want 2 insert the date time into the sql column of data type datetime through servlets dynamically .How 2 do dat
JAVA JSP and Servlet - JSP-Servlet
JAVA JSP and Servlet  for sending mail through lan without intenet and also chatting facility for online users using Java JSP & SERVLET code.  Hi Friend, Please visit the following links: http://www.roseindia.net
java servlet programming - JSP-Servlet
java servlet programming  when i m inserting an image file into the sql table in a column of data type binary using prepared statement ps.setBinaryStream, instead of filename it's displaying
JSP with java/servlet - JSP-Servlet
(java bean or servlet) to fecth the database. Jsp would get the data from...JSP with java/servlet  Thanks Deepak for your answere to my previous.../servlet-jsp-data-list.shtml Hope that it will be helpful for you. Thanks
Java Servlet - Servlet Interview Questions
Java Servlet  My Servlet Program is generating Compile time errors. 1)pakage javax.Servlte.Http.* does not exists. and Pakage javax.Servlte does... be that you have not set the classpath of your java-servlet-api.jar in the environment
java servlet code - Servlet Interview Questions
java servlet code  iam doing a project in java, preparation of on line examination in that how to prepare a question paper using servlet code
java,servlet,jsp - JSP-Servlet
java,servlet,jsp   i am doing a project on online examination system and in that there are problems that-- 1.i want to disable the back,forward and refresh button.Please give me the code for google crome browser. 2.suppose
JAVA - JSP-Servlet
Java servlets sessions session tracking  How to track the session in Servlet
java - JSP-Servlet
java  why is required to write both jsp and servlet in a application of java
java servlet - Java Beginners
java servlet  how to use java servlet? and what the purpose of servlet?  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/ Hope that it will be helpful for you. Thanks
java - JSP-Servlet
Java Servlet Config means   What is Servlet Config means ?  ...://www.roseindia.net/servlets/ServletContext.shtml  Servlet Config means configurion of servlet it is used to cofigure any properties in web.xml and Context
Java Servlet
Java Servlet  how to create the login form using servlets and how to validate the username and password?   Please visit the following link: http://www.roseindia.net/jsp/loginbean.shtml
java servlet compilation error - Servlet Interview Questions
java servlet compilation error  i done the Restart your tomcat server and run your servlet.but i got the problam
java servlet compilation error - Servlet Interview Questions
java servlet compilation error  hello sir plz help me, i compile the servlet program but i got the arrors that errors are package javax.servlet.http..., Put servlet-api.jar into the lib folder of apache-tomcat.And set the class path
java servlet help neeed....
java servlet help neeed....  i have little bit miss concept on servlet and jsp....what ever i know always the jsp provoke first then servlet ...like... the servlet will be called (mapping i have to make in web.xml)......but to some one told
Java script in servlet
Java script in servlet  Hi. How to use javascript inside java servlet? Thanks in advance
java servlet - Servlet Interview Questions
java servlet   i use tomcat server and eclipse as ide for j2ee environment when i tries the example for sevlet context in roseindia to make entry in server log file ( context.log method to log entry) but could not see the log
Java - JSP-Servlet
cmd + (Enter Key) 2. Change the directory to the Servlet file(i.e .java) and 3...Java  What a the steps to compile a Servlet Programe.  Hi... to configure tomcat for running servlet. http://www.roseindia.net/servlets
java charts - JSP-Servlet
java charts  Hi,can any one tell me how to create dyanamic charts wrt database contents by using jsp-servlet
Java Servlet - Development process
Java Servlet  Hello Sir how to set Classpath for Java Servlet.  Hi Friend, Put servlet-api.jar file into the lib folder of apache...:\apache-tomcat-6.0.16\lib\servlet-api.jar For more information, visit
Java servlet sql connectivity error - JSP-Servlet
Java servlet sql connectivity error  Hi, I have been trying to connect to sql database via the servlet program in java.I have not been successful so far. However when i try to connect to sql through a normal java program
java server programming : servlet - JSP-Servlet
java server programming : servlet  hi all, can you help check what's wrong with my servlet that i have a null pointer exception.Thanks ERROR... servlet request * @param response servlet response */ protected
Java Problem - JSP-Servlet
Java Problem  What are the steps to run a java Servlet program.with examples  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/index.shtml Thanks
Java - JSP-Servlet
.. This is a general question. How to compile a servlet program? I need step by step explaination.. MoreOver,I know JAVA to some extent.. But I need to improve my....,) for developing servlet programs? If you are using IDE, it is not much
java - Servlet Interview Questions
java  servlet interview questions  Hi friend, For Servlet interview Questions visit to : http://www.roseindia.net/interviewquestions/servlet/ Thanks
Servlet
Servlet  What is Servlet
java - JSP-Servlet
java  example of session tracking in servlet
Java servlet - Java Beginners
Java servlet  Hello sir, Please send simple Java servlet coding...:\\ folder.Put servlet-api.jar in in the lib folder of your apche-tomcat.Then go...:\apache-tomcat-6.0.16; 2) Classpath=C:\apache-tomcat-6.0.16\lib\servlet-api.jar
servlet prog - Java Interview Questions
servlet prog  how to forward or redirect the client request from servlet to jsp? how a thread or request pass from one servlet prog to one jsp prog? is it possible of communicating from servlet to jsp prog? please explain briefly
Sitemap Java Servlet Tutorial Section
Map | Business Software Services India Java Servlet Tutorial Section... | Snooping Headers | Dice Roller in Java Servlet | Getting Init Parameter... value Using Servlet | Hit Counter Servlet ADS_TO_REPLACE_1 Java Servlet
Servlet
Servlet   Why is Servlet so popular?   Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web
servlet
usin jsp,java class and servlet... help me thanks in advance....   Give me the full coding to upload a file in local drive using jsp,java class and servlet please and thanks in advance
java servlet programmin - JDBC
java servlet programmin  How to dispaly data retrieved from sql table in a tabular form(html)through java servlets??? The database table contains user name,filename(uploaded)and date of uploading. so how to diplay all
java servlet programming - JDBC
java servlet programming  how to insert value in a column of datatype - datetime in sql 2000 using java servlets???? can ne 1 help me out???  Hi neepa, you have to put the datetime in single quotes. For ex
java servlets - JSP-Servlet
java servlets  how to get the parameter value of input type file using java servlets  Hi, You can use request.getParameter(). In Jsp, --- --- IN servlet, String fileName=request.getParameter('fl'); If you
Jtable with servlet - Java Beginners
with servlet code in a java class. where user will enter the information in textboxes... with the servlet, because we cannot extend to class at the same time. Is there any other way to do so.I need help to display the record in JTable with the servlet
servlet - Java Beginners
servlet  hye roseindia..what is the role of servlet with the diagram... servlet performs specific tasks for a web server and returns the results formatted... servlet program acts as a bridge between the web server and some repository
query on java servlet
query on java servlet  hello sir,i am doing online exam using j2ee (i.e) with servlet and back end ms access just like statically after that i will use dynamic connection sir.what queries to be used for data base validation
java - Servlet Interview Questions
Java Design Patterns Interview Questions and Answers  I need to know Java Design Patterns with the help of Interview Questions and Answers  ... implemented Servlet and ServletConfig interface for developing GenericServlet.And also
Java servlet - Java Beginners
Java servlet  Thank you for your kind reply. please send Servlet with JDBC connection code  Hi Friend, We are providing you a code that will connect the servlet to database and insert the data. import

Ads