We help IT Professionals succeed at work.

What's wrong with following code.tryuing to access MS access using JSP

hiteshgupta1
hiteshgupta1 asked
on
Medium Priority
284 Views
Last Modified: 2012-05-05
i've cerated a database names TiH.mdb which has a table named TBL_TBL_FUNCTIONS
in the table there r thrree fields
BUS_FUN_ID,BUS_FUN_NAME,FUN_ID

now i 've just written the following code to access data from the table
but nothing gets displayed
what's wrong with the code??

<html>
<head>
<%@ page
      import = "java.io.*"
      import = "java.lang.*"
      import = "java.sql.*"
%>
<title>
Test
</title>
</head>
<body>
<h1>test</h1>
<% out.println("hello1");
      String      place;
      Connection dbconn;
      ResultSet results;
      PreparedStatement sql;
      int bus_fun_id,fun_id,name;
      String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=

E:\Tools\Tomcat\webapps\examples\TiH\TiH.mdb";
      dbconn = DriverManager.getConnection(database);
      sql = dbconn.prepareStatement("SELECT * FROM TBL_FUNCTIONS");
      results = sql.executeQuery();
      while(results.next())
            {
                  bus_fun_id = results.getInt("BUS_FUN_ID");
                        fun_id = results.getInt("FUN_ID");
                        name = results.getInt("BUS_FUN_NAME");
                        out.println(bus_fun_id);
                  out.println(fun_id);
                  out.println(name);
            }
      %>
</body>
</html>




Kindly help
Comment
Watch Question

Commented:
Make sure it is able to connect to your database and are there any records in your table ?

And change the import to
<%@ page import="java.io.*,java.lang.*,java.sql.*" %>
Top Expert 2006

Author

Commented:
Thanx for ur help

now i m getting following error
Error: 500
Location: /examples/TiH/Temp.jsp
Internal Servlet Error:

javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(Unknown Source)
      at TiH.Temp_1._jspService(Temp_1.java:89)
      at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java)
      at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source)
      at org.apache.tomcat.core.Handler.invoke(Unknown Source)
      at org.apache.tomcat.core.Handler.service(Unknown Source)
      at org.apache.tomcat.facade.ServletHandler.service(Unknown Source)
      at org.apache.tomcat.core.ContextManager.internalService(Unknown Source)
      at org.apache.tomcat.core.ContextManager.service(Unknown Source)
      at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Unknown Source)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:536)

Commented:
its not able to find the .mdb file.
try to give relative path of your .mdb file, avoid giving absolute path.
you should change the path to E:/Tools/Tomcat/webapps/examples/TiH/TiH.mdb
and make sure TiH.mdb is in specified path
CERTIFIED EXPERT
Top Expert 2004
Commented:
Change:

    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=

E:\Tools\Tomcat\webapps\examples\TiH\TiH.mdb";

to

    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=E:\\Tools\\Tomcat\\webapps\\examples\\TiH\\TiH.mdb";

And consider not using Access... ;-)

Tim

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
you should close you connections and resources ath the end of  jsp :)
Top Expert 2006

Author

Commented:
definately sir:)
i'll take care of it!!

Commented:
what was wrong with my solution ?
infact it works fine.
Top Expert 2006

Author

Commented:
avinthm thanx for ur help
actaul rpoblem was with the format in which i was pcefying the path
u said u should write comlete path "e:\tools\tomcat...)
but that didn't solved the problem
the corrcect solution was to write path as "E:\\tools\\tomcat....) ,means i have to use double slashes instead of single


once again thanx for ur concern and sorry too as i could not divide points between two ppl

Commented:
> u said u should write comlete path "e:\tools\tomcat...)
i think u got my point wrong. i asked u to change the path....i have specified forward slash (/) instead of backward slash (\).

Anyway, your problem is solved. Thats more important than points. :)

cheers
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.