File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem connecting to access

 
panindra nath
Greenhorn
Posts: 6
  • 0
  • 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);
}
}
}
 
Herman Schelti
Ranch Hand
Posts: 387
  • 0
  • 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
  • 0
  • 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?
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you create the DSN as a user DSN or a system DSN?
 
Hareendranath Babu Kotha
Ranch Hand
Posts: 40
  • 0
  • 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.
 
kkk guptha
Greenhorn
Posts: 3
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic