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



Home Answers Viewqa JDBC servlet-jdbc
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shwetappatil
servlet-jdbc
1 Answer(s)      3 years and 10 months ago
Posted in : JDBC


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

public class ServletInsertingDataUsingHtml extends HttpServlet{ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType("text/html"); PrintWriter pw = response.getWriter(); String connectionURL = "jdbc:odbc:shweta"; Connection connection; try{ String username = request.getParameter("username"); String password = request.getParameter("password"); pw.println(username); pw.println(password); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); connection = DriverManager.getConnection(connectionURL); PreparedStatement pst = connection.prepareStatement("insert into emp_info values(?,?)"); pst.setString(1,username); pst.setString(2,password); int i = pst.executeUpdate(); if(i!=0){ pw.println("
Record has been inserted"); } else{ pw.println("failed to insert the data"); } } catch (Exception e){ pw.println(e); } } **//where my dsn name is shweta,database name is db1 and table name is emp_info. i am getting 404 error that is requested resource not available. is there a error in database connectivity or in my program logic?please let me know as soon as possible**


Advertisement
View Answers

January 5, 2011 at 1:35 PM


Hi Friend,

Follow these steps:

1)Go to the start->Control Panel->Administrative Tools-> data sources.

2)Click Add button and select the driver Microsoft Access Driver(*.mdb).

3)After selecting the driver, click finish button.

4)Then give Data Source Name and click ok button.

5)Your DSN will get created.

6) Compile your servlet and restart the server and run your servlet.

Here is your required servlet code:

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

public class ServletInsertingDataUsingHtml extends HttpServlet{ 
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        response.setContentType("text/html"); 
        PrintWriter pw = response.getWriter();
        String connectionURL = "jdbc:odbc:student"; 
        Connection connection; 
        try{ String username = request.getParameter("username"); 
        String password = request.getParameter("password");
        pw.println(username); 
        pw.println(password);
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        connection = DriverManager.getConnection(connectionURL); 
        PreparedStatement pst = connection.prepareStatement("insert into login(username,password) values(?,?)");
        pst.setString(1,username); 
        pst.setString(2,password);
        int i = pst.executeUpdate();
        if(i!=0){
        pw.println("Record has been inserted"); 
        } 
        else{
            pw.println("Failed to insert the data");
            } 
            }
            catch (Exception e){ 
                pw.println(e);
                } 
                }
}

Here student is our dsn and login is our database table.

Thanks



Related Tutorials/Questions & Answers:
servlet-jdbc
servlet-jdbc  import java.io.*; import java.lang.*; import java.sql...."); PrintWriter pw = response.getWriter(); String connectionURL = "jdbc:odbc:shweta.... 5)Your DSN will get created. 6) Compile your servlet and restart the server
servlet - JDBC
= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","scott... con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle... and password but "jdbc:oracle:thin:@localhost:1521:oracle" in this url line
Advertisements
regarding ms acces database and servlet - JDBC
a servlet i got a sqlexception saying datasource not found and it told some thing about... name (e.g emp) 6. Click "Ok" and then try the following Servlet code where...("sun.jdbc.odbc.JdbcOdbcDriver"); connection = DriverManager.getConnection("jdbc:odbc
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
Online quiz mini project
Online quiz mini project  Sir i need a online quiz program coding using java servlet, jdbc odbc connection with ms. access. If possible send that source code to me. Thank you
JAVA - JDBC
JAVA  WRITE A PROGRAM USING SERVLET AND JDBC FOR DEVELOPING AN ONLINE APPLICATION FOR THE SHOPPING OF COMPUTER SCIENCE BOOK.YOU HAVE TO CREATE... the following links to have sample Servlet and JDBC applications. http
problem in creating web application using servelet, jsp, jdbc and xml - JSP-Servlet
problem in creating web application using servelet, jsp, jdbc and xml  Using Servlet, JSP, JDBC and XML create a web application for a courrier... the technologies JSP,Servlet and JDBC etc... Thanks
J2EE - Java Server Faces Questions
On http://www.roseindia.net/ * JSP * Servlet * JDBC
i can not connect to database in servlet - JSP-Servlet
the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting..."); PrintWriter out = response.getWriter(); out.println(""); out.println("Servlet JDBC"); out.println(""); out.println("Servlet JDBC"); out.println
i can not connect to database in servlet - JSP-Servlet
the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting...(""); out.println("Servlet JDBC"); out.println(""); out.println("Servlet JDBC... offer .   Hi friend, Code to connect to database in servlet
JSP-Servlets-JDBC
be JSP-->Servlet-->JDBC-->Services-->JSP 3, Update - The table created... should be navigated to a Servlet page and then the data should be passed to the database table using JDBC and DAO. 2, View - The table created in the database
execution of java program
of the servlet-jdbc program on tomcat 5.5 server.. PlS provide..the execution steps... Foundation\Tomcat 5.5\common\lib\servlet-api.jar";"C:\Program Files\Apache Software..."; is this correct way ?THANKYOU!!!   Put servlet-api.jar and mysql-connector.jar
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
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting to a databse by a servlet.I used the example in "Inserting Data In Database table
error got minus one from read call - JSP-Servlet
JDBC"); out.println(""); out.println("Servlet JDBC...error got minus one from read call  hiiii while connecting my servlet...) the code is as follows: // *DataBase Connectivity from the Servlet. import
What's New?
Servlet, JDBC, Hibernate, Struts 1, Struts 2, JSF, Spring... | Java Servlet Tutorial  | Java Swing Tutorial | JEE 5 Tutorial  | JDBC Tutorial  | J2ME Tutorial | JSP Tutorial | Core
servelet and jdbc programming - XML
servelet and jdbc programming  Write a program using Servlet and JDBC...;   Step 2 : create a servlet class "Student.java...(); String connectionURL = "jdbc:mysql://localhost/zulfiqar"; Connection
Java Developer Training
and work there way up. The Java Developer training program includes the Servlet, JDBC, JSP, Hibernate, Struts, Java Framework, etc. These are the advance
styling jsp - JSP-Servlet
these links very useful. Core Java JSP Servlet JDBC Hibernate
How to delete the row from the Database by using while loop in servlet
Servlet (JDBC). you entered 'ramanujan' is 9 character but in the database... server database by using Servlet program (Tomcat server). In Database table..."); Connection c=DriverManager.getConnection("jdbc:odbc:hari","raman
Tomcat Quick Start Guide
advance JSP and Servlets. Resources for advance study: JSP Servlet JDBC... application using JSP, Servlets and JDBC technologies. In this quick and very... exploration! Tomcat JSP  and servlet Tutorial sections: Introduction
JSP CRUD Application
the table. We can also create a CRUD application using JSP, Servlet, And the JDBC. Example Here we will create a CRUD application using Java Servlet, JSP, and the JDBC. We will understand here the basic purpose of creating a CRUD
 

 

 

DMCA.com