?
Solved

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

Posted on 2006-04-10
9
Medium Priority
?
260 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
0
Comment
Question by:hiteshgupta1
9 Comments
 
LVL 6

Expert Comment

by:avinthm
ID: 16424068
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.*" %>
0
 
LVL 8

Author Comment

by:hiteshgupta1
ID: 16424129
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)

0
 
LVL 6

Expert Comment

by:avinthm
ID: 16424422
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Accepted Solution

by:
TimYates earned 375 total points
ID: 16424512
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
0
 
LVL 2

Expert Comment

by:borislavmarkov
ID: 16424599
you should close you connections and resources ath the end of  jsp :)
0
 
LVL 8

Author Comment

by:hiteshgupta1
ID: 16424616
definately sir:)
i'll take care of it!!
0
 
LVL 6

Expert Comment

by:avinthm
ID: 16424655
what was wrong with my solution ?
infact it works fine.
0
 
LVL 8

Author Comment

by:hiteshgupta1
ID: 16425232
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
0
 
LVL 6

Expert Comment

by:avinthm
ID: 16425474
> 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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question