JDBC-SERVLET

JDBC-SERVLET

*while doing connectivity of jdbc with servlet I m getting following error how can I solve it.
*database is saved in classes where .java and .class file is stored. 
*I have done settings of Odbc driver as follows
1)control panel-> administrative tools->ODBC driver->add ->Microsoft Access Driver(*.mdb)->finish->Typed source name->clicked on select- took respective path where database was saved-> ok->ok->ok.

***********My code is******** 
<html>
<body>
<form action="servlet/Samplem"method=GET>
Model No=<input type=text name=mdlno><br>
Mobile Name=<input type=text name=mblnm><br>
Price=<input type=text name=prc><br>
<input type=submit>
</form>
</body>
</html>
***************java code***************
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Samplem extends HttpServlet implements Servlet
{
    public void doGet(HttpServletRequest rq,HttpServletResponse rs)throws ServletException,IOException
        {
        PrintWriter pw=rs.getWriter();


        PreparedStatement pst;



        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
        pw.println("Class loaded");
        Connection cn=DriverManager.getConnection("jdbc:odbc:{Microsoft Access Driver(*.mdb)}");
        pw.println("connected");
        pst=cn.prepareStatement("insert into mobile values(?,?,?)");


        String Mdlno=rq.getParameter("mblno");
                    String Mbnm=rq.getParameter("mbnm");
        String price=rq.getParameter("price");
        pst.setInt(1,Integer.parseInt(Mdlno));
        pst.setString(2,Mbnm);
        pst.setInt(3,Integer.parseInt(price));
                     pst.executeUpdate();

                        pw.println("Inserted");

                                      pst.close();
        cn.close();

        }
        catch(Exception e){pw.println("error"+e);}
        } 
}

****************output**************
Class loaded
errorjava.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
View Answers

March 14, 2013 at 6:26 PM

Go through the link, may this will be helpful for you.

Database Connectivity in Servlet

Thanks.


March 16, 2013 at 2:01 PM

Hi problem with url this url jdbc:odbc:{Microsoft Access Driver(*.mdb)}

First set the datasoruce name in conntrollpannel->Administrative tools -> Datasource(ODBC) -> User DSN-> Add -> select the Microsoft Access Driver(*.mdb) -> finish -> enter some userdefine datasource name like msdsn -> ok.

and use that datasource name in url like

jdbc:odbc:msdsn


March 18, 2013 at 1:16 PM

i tried the program,but still the connectivity with database is not happening. The Driver is getting Loaded.


March 18, 2013 at 1:17 PM

Thank u for you solution









Related Tutorials/Questions & Answers:
JDBC-SERVLET
JDBC-SERVLET  *while doing connectivity of jdbc with servlet I m.... ***********My code is******** <html> <body> <form action="servlet... class Samplem extends HttpServlet implements Servlet { public void doGet
JDBC-SERVLET
JDBC-SERVLET  while doing JDBC connectivity with servlet my driver is getting load but its giving exception for connection that DSN name not found...://www.devmanuals.com/tutorials/java/servlet/ConnectDb.html Thanks
Advertisements
Expport data into CSV File using JDBC in Servlet
into CSV File using JDBC in Servlet   ... into CSV file using JDBC in Servlet. We have created  file "...; in the database.ADS_TO_REPLACE_2 Step 1: Create a Servlet "
Example
Example  JDBC in Servlet examples.   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Servlet Tutorials Here you will get lot of examples including jdbc servlet examples. ThanksADS_TO_REPLACE_2
JAVA - JDBC
JAVA  HOW TO CONNECT JDBC IN SERVLET AND HOW TO PREPARE WEB.XML   Hi Friend, Please visit the following links: http://www.roseindia.net/servlets/ServletInsertingData.shtml http://www.roseindia.net/servlets
Java : Servlet Tutorials - Page 2
into CSV File using JDBC in Servlet In this section, you will learn how to export data into CSV file using JDBC in Servlet. We have created ... Java : Servlet Tutorials     
Sitemap Java Servlet Tutorial Section
File using JDBC in Servlet | Stored Data in XML File using Servlet | Upload... Map | Business Software Services India Java Servlet Tutorial Section... is a Container | What is servlet? | Methods of Servlet |  Life Cycle

Ads