I'm Miguel Angel Llado, a Java programmer and Network Administrator.
First, sorry for my english. I have visited your web page about Jdbc and
I found it very useful and so interesting. In your web page, you put a
link to a Java driver client/server solution to access remote databases.
This software is called RmiJdbc. I have tried this software and I found
it very useful (well, like your web page). But I found a big problem in
RmiJdbc web site: the installation notes about RmiJdb are poor. I would
like to explain you (if you are interested) and other people (you can publish
my notes if you want) the correct installation and examples to use the
RmiJdbc driver. It follows:
Regards,
Miguel Angel
Note: I've made a couple of changes to Miguel's letter, in the hope
of making things clearer. -- Kurt B.
1. Set Up Machine for Database Access and Register Database Database
Access (ODBC):
This instructions are explained in the JDBC web
page.
2. Set Up JDBC and JDBC-ODBC
This is also described on the page referred to above.
3. Install RmiJdbc
Download RmiJdbc
software. This software comes in two formats: gzip compressed and jar
archive. If you download gzip file, uncompress it with gzip -d 4. Update Your CLASSPATH, or Move RmiJdbc.jar into your current CLASSPATH
To your classpath, open the Windows NT Control Panel, open the System
folder, and then choose the Enviroment tab. Set your CLASSPATH to this
value (remember, the CLASSPATH must define complete path of your classes,
including JDK classes; this is very important):
You don't need restart Windows NT, but you must close your DOS window
and open it again to reflect classpath changes.
5. Launch rmiregistry
Now, you are prepared to launch RmiJdbc server driver. First, open an
MS-DOS console, change to then JDK "bin" directory and run rmiregistry.exe.
Nothing apparently happens. Don't worry, the registry is updated.
6. Launch RmiJDBC server
Open another MS-DOS window, go into JDK bin directory and type:
7. Install RMIJdbc on Clients
After you build this example, you can launch it using java.exe or appletviewer.exe
in other machines connected to the database host on your local lan or the
internet. But, remember: you need have RmiJdbc.jar in the classpath
of these machines.
In Netscape, you need copy RmiJdbc.jar in Netscape directory, in
\program\java\classes, in client machine. The database server, along
with the applets, must be on an http server and the class files must be
there.
Alternately, you can include the RMIJdbc classes with your class files,
so that they are downloaded to the browser whenever your applet is downloaded.
This is slower (the file is about 900 K). Remember you must
use the ARCHIVE attribute of the applet tag to use a JAR file.
(ARCHIVE=RMIJdbc.jar)
A programmer I've worked opened up the RMI jar file and removed only
the bare essentials needed for the client. That jar file is at this
location. It should eliminate the need to put RmiJDBC.jar
into the browser's class directories. Note: this
JAR file appears to work, but it has not been heavily tested, nor is it
an official part of RmiJDBC. --kurt b.
Note:
What follows is a simple example application and a sample applet for
testing RmiJDBC . The RmiJDBC site contains a sample,
also. A somewhat more elaborate example included in these files:
Sample Application
Well, that's all. I hope this helps. For more information, please e-mail
me: Miguel Angel Llado
**********************************************
ICCE-Ciberaula
Miguel Angel Llado Caballero
Network Administrator - UNIX Systems
Telephon Number: +34 1 725 72 00
**********************************************
(Tested in Windows NT 4.0 Server and with Sun JDK 1.1.6 package.)
.;[JDK bin absolute path]\..\classes;[JDK bin absolute path]\..\lib\classes.zip;c:\clases\RmiJdbc.jar
Note: Different users will have different directories in their CLASSPATHs.
The CLASSPATH listed here shows only what is essential for using Java and
RmiJdbc. --kurt b.
java RmiJdbc.RJJdbcServer sun.jdbc.odbc.JdbcOdbcDriver
Wait for RmiJdbc server driver messages. When you see something like "RmiJdbcServer
bound in rmiregistry...", your server has been launched succesfully.
the RmiJdbc Server uses internet names resolution, so be sure that
your LAN has a DNS server. If it doesn't, add the LAN client names and
the name of database server to the host file of database server, and add
the same to host file of client machine. If you don't do this, the data
access can take a loooong time.
rjdemormi.java
RmiJDBCDemo.html
RmiDemo.jar
.
-------------------------------cut here--------------------------------
import java.sql.*;
class test {
static public void main(String args[]) {
Connection con;
Statement sentence;
ResultSet result;
System.out.println("Starting Program...\n");
try {
Class.forName("RmiJdbc.RJDriver").newInstance();
} catch (Exception e) {
System.out.println("Can't load Rmi Driver.");
return;
}
try {
// Database URL. Tested with MS-Access 97.
String url = "jdbc:odbc:test";
// Database Host. IP number or Internet name, and port number.
// RmiJdbc server installs it own in port 1099. You can change
this starting the server like this:
// java RmiJdbc.RJJdbcServer -port [your port number]
sun.jdbc.odbc.JdbcOdbcDriver
String rmiHost = new String("//myhost:1099");
// Connection.
con = DriverManager.getConnection("jdbc:rmi:" + rmiHost + "/" +
url, "", "");
sentence = con.createStatement();
try {
result = sentence.executeQuery("SELECT * FROM TestTable");
while (result.next()) {
String field1 = result.getString("TestField1");
String field2 = result.getString("TestField2");
System.out.println(field1 + " " + field2);
}
} catch (SQLException e) {};
} catch (Exception e) {
System.out.println("Something bad happen: " + e);
return;
}
}
}
----------------------------------cut here-----------------------------------------
Tested with Netscape Navigator 4.03 and appletviewer.-----------------------------------cut here----------------------------------------
import java.sql.*;
import java.awt.*;
import java.applet.Applet;
public class testapplet extends Applet {
Connection con;
Statement sentence;
ResultSet result;
String field1;
String field2;
TextArea status;
Label comment;
public void init() {
comment = new Label("Database Results:");
status = new TextArea("Launching program...\n", 10, 35);
setLayout(new FlowLayout(FlowLayout.CENTER));
add(comment);
add(status);
status.appendText("Connecting Database.\n");
try {
Class.forName("RmiJdbc.RJDriver").newInstance();
} catch (Exception e) {
//estado.appendText("Error: " + e);
// above changed by kurt b. to:
status.appendText("Error: " + e);
return;
}
try {
// Database URL.
String url = "jdbc:odbc:test";
// Database Host. IP number or Internet name, and port number.
// RmiJdbc server installs it own in port 1099. You can change this starting the server like this:
// java RmiJdbc.RJJdbcServer -port [your port number] sun.jdbc.odbc.JdbcOdbcDriver
String rmiHost = new String("//myhost:1099");
// Connection..
con = DriverManager.getConnection("jdbc:rmi:" + rmiHost + "/" + url, "", "");
sentence = con.createStatement();
try {
result = sentence.executeQuery("SELECT * FROM TestTable");
while (result.next()) {
field1 = result.getString("TestField1");
field2 = result.getString("TestField2");
status.appendText(field1 + " " + field2 + "\n");
}
} catch (SQLException e) {};
} catch (Exception e) {
status.appendText("Error: " + e);
return;
}
} // init
}
----------------------------------------------cut here-------------------------------------