• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding database connectivity in servlets

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I m trying to access database(Sql server) from servlet class using type 1 driver(odbc) but it is giving the following exception

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

please someone tell me how to fix this problem

Thankyou
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you you put the driver library file (jar)?
 
Manoj Kumar Ravikanti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Mr Souther,

Thanks for replying, I haven't used any driver class(jar)I used Odbc from data sources in the control panel to establish the link for database using a dsn name.

Should I use libary classes for connecting

Regards
Manoj Ravikanti
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, no jar is required in case of type 1 driver.

How did you create the DSN? Can you post the whole step?
 
Manoj Kumar Ravikanti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi rathi ji,

Thanks for replying I have created the dsn name in the following way

I have selected DataSources from control panel then
I have selected add then I have selected the driver as Sql Server,clicked finish
then i have given data source name as link
then i have selected the my system server and the database name from which i have implemented, then i have given the authentication from sql
then i said ok
then i have tested the data source which gave me Data Source test successfull

which I have implemented in my servlet class as following

Yes, no jar is required in case of type 1 driver.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class OnlineEx1 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();

int id=Integer.parseInt(req.getParameter("id"));

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc:NIKE","sa","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from myemp where eid= "+id);
}
catch (Exception e)
{
out.println(e);
}
..............................
...........................

Thankyou,

Regards
Manoj Ravikanti


How did you create the DSN? Can you post the whole step?
--------------------
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Connection through DSN:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:DSN_Name","username","password");

To create DSN:

programs -> settings -> control panel -> administrative tools -> data sources (ODBC)

create a new DSN here.


[ August 23, 2006: Message edited by: rathi ji ]
 
Manoj Kumar Ravikanti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your quick reply,

But can you help me how to create a DSN in the middle of the code..

Thankyou

Regards,

Manoj Ravikanti
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic