aspose file tools*
The moose likes Servlets and the fly likes Accessing data in MS access via servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing data in MS access via servlet" Watch "Accessing data in MS access via servlet" New topic
Author

Accessing data in MS access via servlet

Bhagya sri
Greenhorn

Joined: Nov 09, 2004
Posts: 5
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. Following 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

Bhagya Sri
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hmm. Ever had the feeling you've seen a question before? Oh yes I have. Your servlet still seems to be trying to load a MIME-type rather than a JDBC-ODBC driver class. Try sun.jdbc.odbc.JdbcOdbcDriver instead.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing data in MS access via servlet