SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

105 lines
3.0 KiB

/*
* Created on 21.06.2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package de.memtext.db;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.util.Iterator;
import java.util.List;
/**
* @author MB
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DbRmiClient {
private DbServerI dbServerI = null;
String name = "DbServer"; //"//localhost/DbServer"
public DbRmiClient() {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
dbServerI = (DbServerI) Naming.lookup(name);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NotBoundException e) {
e.printStackTrace();
}
}
public void test() {
testUpdate();
testQuery();
}
private void testUpdate() {
try {
DbRequest dbRequest = new DbRequest("update dummy set col2=99");
DbResponse dbResponse = dbServerI.execute(dbRequest);
if (dbResponse.isOK()) {
System.out.println("OK - updated rows :" + dbResponse.getUpdatedRowsCount());
} else {
System.out.println("failed :" + dbResponse.getException());
}
} catch (Exception e) {
System.out.println(" exception: " + e.getMessage());
e.printStackTrace();
}
}
private void testQuery() {
try {
DbRequest dbRequest = new DbRequest("select * from dummy");
DbResponse dbResponse = dbServerI.executeQuery("select * from dummy");
if (dbResponse.isOK()) {
System.out.println("OK");
List result = (List) dbResponse.getResult();
System.out.println("rows:" + result.size());
int i = 0;
for (Iterator it = result.iterator(); it.hasNext();) {
List row = (List) it.next();
i++;
System.out.print("row " + i + " ");
for (Iterator it2 = row.iterator(); it2.hasNext();) {
Object o = it2.next();
System.out.print(" - " + o);
}
System.out.println("");
}
} else {
System.out.println("failed :" + dbResponse.getException());
}
} catch (Exception e) {
System.out.println(" exception: " + e.getMessage());
e.printStackTrace();
}
}
public static void main(String a[]) {
DbRmiClient c = new DbRmiClient();
c.test();
}
}