Solved

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

Posted on 2004-10-11
8
692 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

930 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

10 Experts available now in Live!

Get 1:1 Help Now