Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing data in MS access via servlet

 
Bhagya sri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic