Solved

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

Posted on 2004-10-11
8
689 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
  • 5
  • 3
8 Comments
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
> "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
Comment Utility
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
Comment Utility
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
 
LVL 12

Accepted Solution

by:
Giant2 earned 400 total points
Comment Utility
>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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:mindweaver
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
:)
Happy to help you.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now