• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

problem connecting to access  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,this my servlet code for retreiving contents from the database using ms-access......whenever i launch browser and type in the URL it throws an error


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

so what should be the remedy to this problem?

thanks...




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

public class test extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{

response.setContentType("text/html");
PrintWriter pw = response.getWriter();
Connection connection=null;


try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbcdbc:db2");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select * from emp");
while(rs.next())
{
pw.println(rs.getString(1));
pw.println(rs.getString(2));
pw.println(rs.getString(3));
pw.println();
}
}
catch (Exception e)
{
pw.println(e);
}
}
}
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

did you define a datasource (see settings - control panel - administrative tools).

Don't understabd why you want to call it db2.

Herman
 
panindra nath
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
YES i did,i selected ms access driver(*.mdb)
User data source as db2
database c:\db2.mdb;

The statement /*connection = DriverManager.getConnection("jdbcdbc:db2");*/ is throwing the exception.... so i think there s something wrong with the path "jdbcdbc:db2".Can you please send me correct path ? Do i need to install any driver for connecting servlet to ms-access?
 
Sheriff
Posts: 21459
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you create the DSN as a user DSN or a system DSN?
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I also got the same problem, but it got resolved once i selected System DSN instead of User DSN. So, trying with System DSN will resolve your problem.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For MS-Access connection,
-- First you have to register DSN and make username and password there.
-- After that link the database of your application to that DSN.
-- In the connection statement, mention as
connection myconn = DriverManager.getConnection("jdbcdbcSNname","username","password");



---KKK Guptha
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!