• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding database connectivity in servlets

 
Manoj Kumar Ravikanti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Connection through DSN:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbcdbcSN_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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic