www.webdeveloper.com
Results 1 to 2 of 2

Thread: Accessing data in MS Access via a servlet

  1. #1
    Join Date
    Nov 2004
    Posts
    7

    Accessing data in MS Access via a servlet

    I have created a form where the users can fill in their details. I would like to capture that data using MS access database and HTTP server via a servlet. Here is the servlet.

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

    public class emp extends HttpServlet
    {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    {
    Connection con=null, con1=null;
    res.setContentType("text/html");
    PrintWriter toClient = res.getWriter();


    String l_delegatename = (String)req.getParameter("delegatename");

    String l_coursename = (String)req.getParameter("coursename");




    try
    {
    Class.forName("application/mdb.ms-access");

    con1 = DriverManager.getConnection("jdbcodbc:TEST", "scott", "tiger");

    Statement stmt1 = con1.createStatement();

    stmt1=con1.createStatement();

    toClient.println("<html>");
    toClient.println("<HEAD>");

    String insertTd = "insert into emp_table values('"+l_delegatename+"','"+l_coursename+"',\"testing\", 1, \"YES\")";

    int count = stmt1.executeUpdate(insertTd);

    stmt1.close();

    if (count > 0)
    {
    toClient.println("<br><center>");
    toClient.println("<font size=\"5\"><b>New User is created successfully</b/></font>");
    toClient.println("</center>");
    }

    toClient.println("</body>");
    toClient.println("</html>");

    }catch(ClassNotFoundException e)
    {
    System.out.println("Couldn't load database driver: " + e.getMessage());
    }
    catch(SQLException e)
    {
    toClient.println("<H3><center>Thank you for submitting the form</center></H3><br>");
    }
    finally
    {
    try
    {
    if (con1 != null) con1.close();
    }
    catch (SQLException ignored) { }
    }
    }
    }

    I think I am not able to give the connection correctly. I am not sure of the following statements in the servlet.

    Class.forName("application/mdb.ms-access");

    con1 = DriverManager.getConnection("jdbcodbc:TEST", "scott", "tiger");


    Could anybody help me in correcting these statements please.

    Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    Class.forName("application/mdb.ms-access");
    I'm pretty sure that needs to be a reference to the jdbc/odbc bridge and that you have to have a system data source defined for the Access db. I'd recommend, though, that you use a real database manager. Both HSQL and Cloudscape/Derby are pure Java and free.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles