aspose file tools*
The moose likes Servlets and the fly likes storing servlet output data in MS Access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "storing servlet output data in MS Access" Watch "storing servlet output data in MS Access" New topic
Author

storing servlet output data in MS Access

Bhagya sri
Greenhorn

Joined: Nov 09, 2004
Posts: 5
Hello all

I created an on-line application form which the users fill in with their details. When they submit this form, I want to capture the data in MS Access using MS Access database via a servlet.

Could anybody tell me how to write the servlet please.


Thanks very much
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sounds like you need to look at the Servlet Tutorial. Its unlikely anyone here will just give you the code, but they will help if you get stuck writing it yourself. What you need to do is read up on how servlets work, so you can understand how you can collect the data passed from your form. Then you'll need to read up on JDBC so you can understand how you can persist it in a database. Good luck.
[ November 12, 2004: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bhagya sri
Greenhorn

Joined: Nov 09, 2004
Posts: 5
Here is the servlet if you can help.

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"jdbc dbc: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) { }
}
}

}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Do you have a specific problem, or are you just looking for general comments on how you've implemented this? If you have a specific problem, describe it and post any error message you are seeing (if there is one).
Bhagya sri
Greenhorn

Joined: Nov 09, 2004
Posts: 5
I am not sure about the following statements

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

con1 = DriverManager.getConnection"jdbc dbc:TEST", "scott", "tiger");

I can't see any data being transferred onto MS Access datasheet.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes that looks wrong. "application/mdb.ms-access" looks like a MIME-type, which is nothing to do with JDBC. What you are doing with that line is loading a suitable Driver to use. You need to find the full name of the Driver you are using (it will be in its documentation) and put it in there.

This:

looks like garbage as well. Your Driver documentation should tell you the correct URL format you need to connect to Access.

For future reference, its unlikely you'll see any insert happen in the database, but there will be an exception stack trace being logged somewhere (I don't know which servlet container you are using, so I can say for sure where). It should tell you what's going wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing servlet output data in MS Access