Share on Google+Share on Google+

Priti Satish Khandve
JDBC-SERVLET
4 Answer(s)      4 years and a month ago
Posted in : JSP-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

Ads

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 ".... Step 1: Create a Servlet "JdbcCsvFile.java"
Example
Example  JDBC in Servlet examples.   Hi Friend, Please visit the following link: Servlet Tutorials Here you will get lot of examples including jdbc servlet examples. Thanks
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
data into CSV File using Servlet | Export data into CSV File using JDBC... Map | Business Software Services India Java Servlet Tutorial Section... is a Container | What is servlet? | Methods of Servlet |  Life Cycle
Tutorials   
Java Spring Hibernate Struts Training fat image from db fat image from db fat image from db fat image from db unable to get value returned from javascript variable in page How to change image size before adding to mysql using jsp Design a registration.jsp page with input for user registration details Cart Quantity jsp servlet coding issue servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? image pdf marking pdf marking Multiple image upload using JSP Read code from excel sheet and upload into database using JSP Student java about search engine Convert BLOB to PDF and save it to a location how to copy files from remote to local machine using SFTP SSL in java? Like Team viewer Socket and Servert -Jsp how to copy files from remote location to local using java? How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java how to create SOAP based web service in java? how to fetch data from mysql database table and draw a bar chart on that data using in jsp how to create users in LDAP using java? how to authenticate user using TIVOLI api in java? how to create users using IBM Tivoi API in jsp/servelet? Java/J2ee Please explain this code as many packages and classes are unknown to me .! how to download the uploaded folder files using jsp Login Query image is display from path of mysql database please reply the code to store dynamic fields in database? Reloading issue in jsp How to get Button Id ? calling one jap page from another jsp page login login Problem to get connection from DAO class to JDBC Page Loading Time Fix table's column's name row(1st row of the table) so that it does not move up when the table is scrolled up to view more rows below Sending hidden values

Ads

 
Advertisement null

Ads