0

I wrote a program to access database But i'm trying to run this but it's giving me some errors pls help:

and here is my user3.html

<html>
<body bgcolor="green">
<center>
<h1>Demo </h1>
<form action="/DatabaseAccess" method="post">
<input type="submit" value="submit">
</form>
</center>
</body>
</html>

here is web.xml

  <web-app>
  <servlet>
  <servlet-name> DatabaseAccess</servlet-name>
  <servlet-class>DatabaseAccess</servlet-class>

  </servlet>
  <servlet-mapping>
    <servlet-name>DatabaseAccess</servlet-name>
     <url-pattern>/DatabaseAccess</url-pattern>
   </servlet-mapping>
   </web-app>

and here is my javafile DatabaseAccess.java

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

 public class DatabaseAccess extends HttpServlet
 {
     public void doPost(HttpServletRequest request,HttpServletResponse    response) throws ServletException, IOException
      {
       // JDBC driver name and database URL

    final String JDBC_DRIVER="sun.jdbc.odbc.JdbcOdbcDriver";  
        final String DB_URL="jdbc:oracle:thin:SYSTEM@localhost:1522:ORCL";

      //  Database credentials

    final String USER = "SYSTEM";
        final String PASS = "BusinessAnalysis";

     // Set response conntent type

    response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String title = "Database Result";
    String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +  "transitional//en\">\n";
        out.println(docType +  "<html>\n" + "<head><title>" + title + "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n" +
                "<h1 align=\"center\">" + title + "</h1>\n");
        try
    {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:ORACLE_DSN", "SYSTEM", "BusinessAnalysis");
         Statement stmt = con.createStatement();

                           // send a SQL query to retrieve records
            ResultSet res = stmt.executeQuery("select * from praveen");
                                            // process the data
            while(res.next())
            {
                System.out.println(res.getInt("rno") + "\t" + res.getInt("age"));
            }
                                            // close the database connection
         res.close();
            stmt.close();
            con.close();
        }
            catch(SQLException se)
    {
            //Handle errors for JDBC
            se.printStackTrace();
        }
    catch(Exception e)
    {
            //Handle errors for Class.forName
            e.printStackTrace();
        }

   }
} 

I'm getting an error of HTTP status 404- /DatabaseAccess description : The requested resource is not availiable

Help would be appreciated!!

Praveen nani
  • 473
  • 4
  • 6
  • Please provide the errors you get – tomvodi Feb 13 '15 at 09:10
  • Can you show us the error messages? – Jens Feb 13 '15 at 09:10
  • I think you forget to map the servlet path in tags, instead of using as second parameter , try to use foo.DatabaseAccess Please note that you need to specify the complete package, e.g. com.test.DatabaseAccess, OR you can use annotations to map your servlets (which i prefer more) – drgPP Feb 13 '15 at 09:20

0 Answers0