Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-11
8
Medium Priority
?
708 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Accepted Solution

by:
Giant2 earned 1200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

916 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