| Author |
Problem accessing Database from JSP
|
Gaurav Pawar
Ranch Hand
Joined: Sep 12, 2006
Posts: 37
|
|
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 dbc:" + 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
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
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 ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16480
|
|
|
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
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
|
So what error are you getting that leads you to believe that you have a driver issue?
|
 |
Gaurav Pawar
Ranch Hand
Joined: Sep 12, 2006
Posts: 37
|
|
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
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
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
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
You can go back and add them to previous posts by clicking the icon. Hint, hint.
|
 |
Gaurav Pawar
Ranch Hand
Joined: Sep 12, 2006
Posts: 37
|
|
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
|
 |
 |
|
|
subject: Problem accessing Database from JSP
|
|
|