This week's book giveaway is in the Agile forum.
We're giving away four copies of Fixing your Scrum and have Ryan Ripley & Todd Miller on-line!
See this thread for details.
Win a copy of Fixing your Scrum this week in the Agile forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Problem accessing Database from JSP

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a sample Java Program that manipulates a MS Access Database. I have now written JSP code to perform the same functions (insert/ delete.) on the database.

I have my class files under WEB-INF/classes and the database in webapps/MyApp/myDB.mdb

Could you please help me with the following.
1. Is the database placed in the right path.
2. Do i have to place the driver in the WEB-INF/lib? if so which drivers. I did search a lot but could not find a good reference

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName = strDSN;
String dbURL = "jdbc:odbc:" + dataSourceName;
Connection con = DriverManager.getConnection(dbURL, "","");
Statement s = con.createStatement();
s.execute(strQuery);

This is how the code in my java class looks like. This class is called from the JSP.

Can anyone please give me guidelines/ sample example on a JSP accessing a (ms acess) database deployed in Tomcat?

Thanks.
Gaurav
 
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is inappropriate to do DB access from a JSP. You should be using the very non-UI classes that you've already set up in a reusable manner. But yes, once you find out what the correct drivers are, they will go in WEB-INF/lib.
[ March 17, 2007: Message edited by: Bear Bibeault ]
 
Marshal
Posts: 26745
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the driver you plan to use is "sun.jdbc.odbc.JdbcOdbcDriver" then you don't have to put it anywhere. It is already part of the JRE. (Unless you are using a JRE not written by Sun, in which case you will not be able to use it at all.)
 
Bear Bibeault
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what error are you getting that leads you to believe that you have a driver issue?
 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Well my code for accessing the database is in a java class called Starter.java which has a function




and this is what getData() does.


This class is in webapps/MyApp/WEB-INF/classes/core

In my JSP i have the following code.

<%@page import="core.Starter"%>
<%

Starter StMap = new Starter();
StMap.InitializeMap();

%>

The Error: org.apache.jasper.JasperException: Array index out of range: 0


The problem is this works fine as a standalone application.. but after deployment

I have put the database in webapps/MyApp

When i run this in my browser as http://localhost:8080/MyApp/Map.jsp
it gives the error


org.apache.jasper.JasperException: Array index out of range: 0
[ March 18, 2007: Message edited by: Gaurav Pawar ]
 
Bear Bibeault
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When posting code to the forums, please use UBB code tags. Read this for more information.

It's just too hard to read unformatted code.
 
Bear Bibeault
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can go back and add them to previous posts by clicking the icon. Hint, hint.
 
Gaurav Pawar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I got the solution to this one. I had declared the 'Data Source Name' as User DSN. I then tried declaring it as a System DSN and it worked.

Thanks,
Gaurav
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic