Ive sent the original with the source but nothing happend didnt see it so
now I'm just
going to email it without the source.
Figured out how to use the RmiJdbc for a test app:
For anyone who cares or has been stuck trying to get to work:
This is done on windows 2000, using jdbc 1.3
I use the following directory
c:\rmijdbc - root directory
c:\rmijdbc\client - directory where the client app runs from
Here is the source to create the database:
Database.java
// package org.enhydra.instantdb;
import org.enhydra.instantdb.jdbc.*;
import org.enhydra.instantdb.db.*;
import java.sql.*;
import java.util.Vector;
class Database
{
public static Database _Database = null;
public Database()
{
}
public void CreateDatabase()
{
try
{
Connection con;
Statement stmt;
String strSQL;
Class.forName ("org.enhydra.instantdb.jdbc.idbDriver");
con = DriverManager.getConnection ( "jdbc:idb:sample.prp");
stmt = con.createStatement ();
strSQL = "CREATE TABLE employee (";
strSQL += "emplID int AUTO INCREMENT, ";
strSQL += "name CHAR(40)) ";
stmt.execute( strSQL );
stmt.close();
stmt = con.createStatement();
strSQL = "INSERT INTO employee(name) VALUES( 'Fred Flintstone' )";
stmt.execute( strSQL );
stmt.close();
stmt = con.createStatement();
strSQL = "INSERT INTO employee(name) VALUES( 'Barny Rubble' )";
stmt.execute( strSQL );
stmt.close();
stmt = con.createStatement();
strSQL = "INSERT INTO employee(name) VALUES( 'Wilma Flintstone' )";
stmt.execute( strSQL );
stmt.close();
con.close();
}
catch( Exception err )
{
System.err.println( err );
err.printStackTrace();
}
}
public static void main (String args[])
{
try
{
_Database = new Database();
_Database.CreateDatabase();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I use the batch file to compile that database:
Compile.bat
set ProjectPath=c:\rmijdbc
set JarPath=c:\java\jar
set JarFiles=%JarPath%\idb.jar;%JarPath%\jta-spec1_0_1.jar;
set Output=%ProjectPath%
Set Source=%ProjectPath%
del %ProjectPath%\Database.class
@echo on
javac -deprecation -classpath .;%JarFiles% %Source%\Database.java -d
%Output%
Then I run the batch file to create the database:
create.bat
set ProjectPath=c:\rmijdbc
set JarPath=c:\java\jar
set JarFiles=%JarPath%\idb.jar;%JarPath%\jta-spec1_0_1.jar;
@echo on
java -classpath %JarFiles%%ProjectPath% Database
Use the Sample.prp that was in the InstantDb download
NOTE: very inportant you need to create a file db.policy
located at c:\rmijdbc\db.policy
grant
{
permission java.util.PropertyPermission "java.rmi.server.hostname", "read";
permission java.util.PropertyPermission "noBanner", "read";
permission java.util.PropertyPermission "java.vendor", "read";
permission java.util.PropertyPermission "*", "read,write";
permission java.io.FilePermission "${db.root}${/}*", "read";
permission java.io.FilePermission "${db.root}${/}trace.log", "read,write";
permission java.io.FilePermission "${db.root}${/}indexes${/}*",
"read,write,delete";
permission java.io.FilePermission "${db.root}${/}system${/}*",
"read,write,delete";
permission java.io.FilePermission "${db.root}${/}tables${/}*",
"read,write,delete";
permission java.io.FilePermission "${db.root}${/}tmp${/}*",
"read,write,delete";
};
Here is the batch file that will start the rmi server located at c:\rmijdbc
run.bat
set ProjectPath=c:\Temp
set JarPath=c:\java\jar
set
JarFiles=%JarPath%\RmiJdbc.jar;%JarPath%\idb.jar;%JarPath%\jta-spec1_0_1.jar
;
@echo on
rem java -classpath .;%JarFiles% RmiJdbc.RJJdbcServer jdbc.idbDriver
java -classpath
.;%JarFiles% -Ddb.root=c:\\rmijdbc -Djava.security.policy=db.policy
RmiJdbc.RJJdbcServer org.enhydra.instantdb.jdbc.idbDriver
It should start with out any problems
Now on to the client side:
here is the code for TestClient.java
/**
* RmiJdbc client/server JDBC Driver
* (C) GIE Dyade (Groupe BULL / INRIA Research Center) 1997
*
* @version 1.0
* @author Pierre-Yves Gibello (Pierre-Yves.Gibello@inrialpes.fr)
*/
import java.sql.*;
import java.net.InetAddress;
/**
* This is a sample program for RmiJdbc client/server jdbc Driver
* RmiJdbc relies on Java RMI for jdbc objects distribution
*/
public class TestClient {
public static void main(String args[]) {
try {
// Register RmiJdbc Driver in jdbc DriverManager
// The call to newInstance() is necessary on some platforms
// (with some java VM implementations)
Class.forName("RmiJdbc.RJDriver").newInstance();
// Test with InstantDB free java database engine
// See http://www.instantdb.co.uk for info & download
String url = "jdbc:idb:c:\\rmijdbc\\sample.prp";
// RMI host will point to local host
// A port number may be specified as 1st argument to the program
String portSpec = "";
if(args.length > 0) {
Integer.parseInt(args[0]); // Check port number is an integer
portSpec = new String(":" + args[0]);
}
System.out.println( "\r\nTportSpec" );
System.out.println( portSpec );
// String rmiHost = new String(
// "//" + InetAddress.getLocalHost().getHostName() + portSpec);
String rmiHost = "//" + InetAddress.getLocalHost().getHostName() +
portSpec;
System.out.println( "\r\nOutput - rmiHost" );
System.out.println( "\r\n" + rmiHost );
// RmiJdbc URL is of the form:
// jdbc:rmi://<rmiHostName[:port]>/<jdbc-url>
String jurl = "jdbc:rmi:" + rmiHost + "/" + url;
System.out.println( "\r\nOutput - jurl" );
System.out.println( "\r\n" + jurl );
Connection c = DriverManager.getConnection(jurl);
Statement st = c.createStatement();
ResultSet rs = st.executeQuery("select * from employee");
ResultSetMetaData md = rs.getMetaData();
while(rs.next()) {
System.out.print("\nTUPLE: | ");
for(int i=1; i<= md.getColumnCount(); i++) {
System.out.print(rs.getString(i) + " | ");
}
}
rs.close();
} catch(Exception e) {
System.err.println( e );
e.printStackTrace();
}
}
};
compile it compile.bat
set ProjectPath=c:\rmijdbc\client
set JarPath=c:\java\jar
set
JarFiles=%JarPath%\idb.jar;%JarPath%\jta-spec1_0_1.jar;%JarPath%\RmiJdbc.jar
;
set Output=%ProjectPath%
Set Source=%ProjectPath%
del %ProjectPath%\TestClient.class
@echo on
javac -deprecation -classpath .;%JarFiles% %Source%\TestClient.java -d
%Output%
now run it run.bat
set ProjectPath=c:\rmijdbc\client
set JarPath=c:\java\jar
set
JarFiles=%JarPath%\idb.jar;%JarPath%\jta-spec1_0_1.jar;%JarPath%\RmiJdbc.jar
;
@echo on
java -classpath %JarFiles%%ProjectPath% TestClient
it should read the employee table and spit out the data.
I've included 2 files one is a self-extracting exe
another is a zip before creating a self-extrating exe
which ever one you use make sure it extract it to c:\rmijdbc
Hope this helps others and thanks for Peter Hearty for giving me the help
and information.
-----------------------------------------------------------------------------
To unsubscribe from this mailing list, send email to majordomo@enhydra.org
with the text "unsubscribe instantdb" in the body of the email.
If you have other questions regarding this mailing list, send email to
the list admin at owner-instantdb@enhydra.org.
|