Solved

Relative path to MS Access-database (.mdb) on webserver

Posted on 2004-10-11
8
702 Views
Last Modified: 2011-10-03
Hey,

I have been searching and searching but can't find an answer to this question. It should be simple but seems not. I have buildt a news ticker that imports all data (headlines, news content and Urls) from a MS Access-database. Obviously since this is a news ticker and an applet I want it to run on a webserver, but Java won't let me. Java keeps on forcing me to have my database on a local harddrive and/or add Driver connection in the local ODBC. That just won't cut it if I want it to run on a webserver

My question is as follows; is it possible to give my mdb-connection a relative path? or is there any other way to solve this?

My connection looks like this:

          try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Calling the JDBC:ODBC bridge to be able to connect to our MS Access database
            Connection con = DriverManager.getConnection("jdbc:odbc:JollyTickerDatabase");  // creating a connection and reading the database via an ODBC connection made by the installer
            Statement s = con.createStatement(); // creating a java.sql.Statement
            s.execute("SELECT news_caption, news_text, news_link FROM JT_content"); // getting the our text from the database
            ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
            while ( rs.next() ) { // stepping through our data row-by-row
              newsContent.addElement(rs.getString("news_text"));  // adding all rows of textcontent into the newsContent vector
              newsCaption.addElement(rs.getString("news_caption"));  // adding all rows of textcontent into the newsContent vector
              newsURL.addElement(rs.getString("news_link"));  // adding all rows of textcontent into the newsContent vector
            }
            s.close(); // closing the Statement
            con.close(); // closing the Connection
          }
          catch (Exception e) {
            System.out.println("Error: " + e);
          }

In this case  "JollyTickerDatabase" is a DSN that is added as System DSN in the local ODBC and points to  "C:\Program\JollyTicker\jollyticker.mdb"

Please help me solve this.
0
Comment
Question by:mindweaver
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 12

Expert Comment

by:Giant2
ID: 12276813
> "JollyTickerDatabase" is a DSN that is added as System DSN in the local ODBC and points to  "C:\Program\JollyTicker\jollyticker.mdb"

If you cannot have your mdb file over the net reachable by the system, it's really impossible to join it.
If you have the DB over the machine XYZ, you can join it if you declare the directory (or path) where the mdb file is like shared. In this manner each machine over you net can see it (following the permission you give to the dir/path). So you can point to this dir/file from the DSN for ODBC.

Bye, Giant.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12276849
You can point even not using DSN, but you must specify the path where the mdb file is.
So the final solution is:
point to a share path where you put the mdb file.
OR
change the DB.


Hope this could help you.
Bye, Giant.
0
 

Author Comment

by:mindweaver
ID: 12276964
Sorry, I must have confused you :) look at the connection I paste now! This points to a local dir where the databse is located, this will never work when I later upload it to a webserver. what I want is to be able to give it a relative path. like  "/db/jollydb.mdb" instead of "C:\Program\JollyTicker\jollyticker.mdb"

          try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Calling the JDBC:ODBC bridge to be able to connect to our MS Access database
           
            String filename = "C:/Program/JollyTicker/jollydb.mdb";
            String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
            database+= filename.trim() + ";DriverID=22;READONLY=true}";
            Connection con = DriverManager.getConnection( database ,"","");
           
            Statement s = con.createStatement(); // creating a java.sql.Statement
            s.execute("SELECT news_caption, news_text, news_link FROM JT_content"); // getting the our text from the database
            ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
            while ( rs.next() ) { // stepping through our data row-by-row
              newsContent.addElement(rs.getString("news_text"));  // adding all rows of textcontent into the newsContent vector
              newsCaption.addElement(rs.getString("news_caption"));  // adding all rows of textcontent into the newsContent vector
              newsURL.addElement(rs.getString("news_link"));  // adding all rows of textcontent into the newsContent vector
            }
            s.close(); // closing the Statement
            con.close(); // closing the Connection
          }
          catch (Exception e) {
            System.out.println("Error: " + e);
          }
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 12

Accepted Solution

by:
Giant2 earned 400 total points
ID: 12276999
>what I want is to be able to give it a relative path. like  "/db/jollydb.mdb" instead of "C:\Program\JollyTicker\jollyticker.mdb"

use a . notation; so like the following:  ..\..\db\jollydb.mdb
0
 

Author Comment

by:mindweaver
ID: 12277091
Might have worked, but as it seems only in appletviewer. What if I have my

index.html
jollydb.mdb
JollyTicker.jar

in the same directory?

having only;  String filename = "jollydb.mdb";
doesn't work :/
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12277154
normally in a webservice the resource (like DB) are done specifying the context in the server.xml (tomcat for example).
In these positions you can specify the connection you want to use.(see Tomcat documentation of details about it).
If you use directly probably you could have some problem about permission [I have never used in this manner].
0
 

Author Comment

by:mindweaver
ID: 12280722
I gave up and went over to mySQL instead and now it works great :) Thanks for your input though, and as you did answer on how to get relative path, even though it was local, I will grant you with the points.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12284128
:)
Happy to help you.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

623 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