aspose file tools*
The moose likes Servlets and the fly likes cannot access ms access database after loading servlet to tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "cannot access ms access database after loading servlet to tomcat" Watch "cannot access ms access database after loading servlet to tomcat" New topic
Author

cannot access ms access database after loading servlet to tomcat

Vinay Thippeswamy
Greenhorn

Joined: Apr 26, 2006
Posts: 15
hi,
iam new to servlets. iam able to access the database using the java. but if i make that class accessible by a servlet i getr an error. i have created a dsn to the .mdb file. here is the source.

file 1:
say this is the model;

package com.example;

import java.sql.*;

public class dba {

String username = "vinay";
String password = "max";
/*
public static void main(String[] args) {

dba db = new dba();
db.go();
}*/


public void go() {

Connection con;

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc dbc ba");

Statement stmt = con.createStatement();

String query = "SELECT login,pass FROM loginval";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String s = rs.getString("login");
String p = rs.getString("pass");
System.out.println(s + " " + p);
if(s.equals(this.username)&& p.equals(this.password)) {
System.out.println("login successfull");
}


}

}catch(ClassNotFoundException e){

System.out.println(e.toString());
}catch(SQLException e){

System.out.println(e.toString());
}
}

}


2nd file: this is the servlet:

package com.example;

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

public class invoke extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

//String name = request.getParameter("username");
//String pass = request.getParameter("password");

dba db = new dba();
db.go();


}
}


and if i see the contents of the following log file of tomcat 5.5:
E:\sw\tc\logs\stdout_20060620.log it contains:

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

iam expecting the System.out.println to print to this file but database access is not happening. but it happens using main without servlet access or tomcat.

by the way i have placed the .mdb file in the WEB-INF DIRECTORY of the application iam trying to execute while creating the DSN.

what should i do for that error.
thanks for your replies.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18643
    
    8

This may sound like a dumb question, but you did create the DSN on the machine where Tomcat is running, didn't you? And you did configure it with the full path to where you put it in the web application, ending with "...\WEB-INF\something.mdb", right?
Vinay Thippeswamy
Greenhorn

Joined: Apr 26, 2006
Posts: 15
of course i configured the dsn to E:\sw\tc\webapps\dba\WEB-INF when running the app in core java as well as accessing it through a servlet.

please help this is causing a real headache. everything is configured properly. everything in the browser runs fine and i get a blank page as expected, as there are no print writer statements. but in the stdout folder of the tomcat\log directory i dont get the proper out put. in fact the model is not able to access the database at all after calling it from the servlet rateher then calling from the main() in core java. i tried this on 2 systems. xp and win 2000.

thanks for your replies.
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Can you give the whole printStackTrace().

Naseem


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Vinay Thippeswamy
Greenhorn

Joined: Apr 26, 2006
Posts: 15
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.example.dba.go(dba.java:24)
at com.example.invoke.doPost(invoke.java:16)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)


looks like after making the core java file into a model and accessing it through a servlet is somehow making the dsn unavailable i think.

i have created both system dsn and user dsn. still it dosent work. but how can this happen when tomcat is configured to use the same jvm? the default jvm should access the dsn. is there any problem with the location of the mdb file?

thanks
vinay
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
hey, it worked on my system.

I just created user dsn. Placed both the classes invoke and dba in classes folder. Made all the servlet entries in web.xml. Mapped it by *.servlet.

Thats the total configuration which I have made.

My tomcat version is 5.5.8.

I am able to fetch the data from servlet as well as from java program.

Regards

Naseem
Vinay Thippeswamy
Greenhorn

Joined: Apr 26, 2006
Posts: 15
can u post the web.xml as well as what do u mean by map *.servlets? if it works there, it should work here also. can u give me step by step procedure what u did please? also specify which dsn u created and where u placed ur mdb file. by the way here is the web.xml i used.

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www/w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">


<servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>com.example.invoke</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/log.do</url-pattern>
</servlet-mapping>

</web-app>

is it any different then u used. can u do me a favour. can u zip and mail me the complete root folder (webapps/..thisfolder )of your application.
my id is vinay2070@gmail.com

thanks
vinay

[ June 21, 2006: Message edited by: Vinay Thippeswamy ]
[ June 21, 2006: Message edited by: Vinay Thippeswamy ]
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809

specify which dsn u created and where u placed ur mdb file.


I have created user dsn test. Location of mdb file will not matter. You just need to map it by some user dsn.

I sent you my complete project on your email address.

Regards

Naseem
[ June 22, 2006: Message edited by: Naseem Khan ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot access ms access database after loading servlet to tomcat