Solved

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

Posted on 2004-10-11
8
696 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 162
mockito example issue 8 72
Java JRE greater than 1.6 5 62
javap bin 2 34
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

770 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