You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by fu...@apache.org on 2005/01/26 11:27:58 UTC
svn commit: r126495 - /incubator/derby/code/trunk/java/demo/nserverdemo/NsSample.java /incubator/derby/code/trunk/java/demo/nserverdemo/NsSampleClientThread.java /incubator/derby/code/trunk/java/demo/nserverdemo/SimpleNetworkClientSample.java
Author: fuzzylogic
Date: Wed Jan 26 02:27:56 2005
New Revision: 126495
URL: http://svn.apache.org/viewcvs?view=rev&rev=126495
Log:
Allow Network Server demo to compile without db2jcc.jar in the classpath.
Modified:
incubator/derby/code/trunk/java/demo/nserverdemo/NsSample.java
incubator/derby/code/trunk/java/demo/nserverdemo/NsSampleClientThread.java
incubator/derby/code/trunk/java/demo/nserverdemo/SimpleNetworkClientSample.java
Modified: incubator/derby/code/trunk/java/demo/nserverdemo/NsSample.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/nserverdemo/NsSample.java?view=diff&rev=126495&p1=incubator/derby/code/trunk/java/demo/nserverdemo/NsSample.java&r1=126494&p2=incubator/derby/code/trunk/java/demo/nserverdemo/NsSample.java&r2=126495
==============================================================================
--- incubator/derby/code/trunk/java/demo/nserverdemo/NsSample.java (original)
+++ incubator/derby/code/trunk/java/demo/nserverdemo/NsSample.java Wed Jan 26 02:27:56 2005
@@ -12,6 +12,7 @@
import java.sql.SQLException;
import java.sql.DriverManager;
import java.io.IOException;
+import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -70,7 +71,7 @@
// To connect to Derby Network Server
// This URL describes the target database for type 4 connectivity
// Notice that the properties may be established via the URL syntax
- private static final String CS_NS_DBURL= "jdbc:derby:net://localhost:"+NETWORKSERVER_PORT+"/NSSampledb;create=true:retrieveMessagesFromServerOnGetMessage=true;deferPrepares=true;";
+ private static final String CS_NS_DBURL= "jdbc:derby:net://localhost:"+NETWORKSERVER_PORT+"/NSSampledb;create=true;retrieveMessagesFromServerOnGetMessage=true;deferPrepares=true;";
public static void main(String[] args) throws Exception {
@@ -78,7 +79,7 @@
// DB2Connection provides additional functionality than java.sql.Connection
// One can use either depending on the requirements
- com.ibm.db2.jcc.DB2Connection conn = null;
+ Connection conn = null;
PrintWriter pw = null;
@@ -149,7 +150,8 @@
// Get database connection using the JCC client via DriverManager api
try {
- conn = (com.ibm.db2.jcc.DB2Connection) DriverManager.getConnection(CS_NS_DBURL, properties);
+
+ conn = (Connection) DriverManager.getConnection(CS_NS_DBURL, properties);
} catch(Exception e) {
pw.println("[NsSample] Connection request unsuccessful, exception thrown was: ");
pw.println("[NsSample] Please check if all the jar files are in the classpath and the dbUrl is set correctly.");
Modified: incubator/derby/code/trunk/java/demo/nserverdemo/NsSampleClientThread.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/nserverdemo/NsSampleClientThread.java?view=diff&rev=126495&p1=incubator/derby/code/trunk/java/demo/nserverdemo/NsSampleClientThread.java&r1=126494&p2=incubator/derby/code/trunk/java/demo/nserverdemo/NsSampleClientThread.java&r2=126495
==============================================================================
--- incubator/derby/code/trunk/java/demo/nserverdemo/NsSampleClientThread.java (original)
+++ incubator/derby/code/trunk/java/demo/nserverdemo/NsSampleClientThread.java Wed Jan 26 02:27:56 2005
@@ -319,7 +319,7 @@
/**
* Create necessary schema if schema not already created
*/
- public static void checkAndCreateSchema(com.ibm.db2.jcc.DB2Connection conn,PrintWriter pw) {
+ public static void checkAndCreateSchema(Connection conn,PrintWriter pw) {
Statement stmt = null;
ResultSet rs = null;
@@ -378,7 +378,7 @@
/**
* Loads schema , inserts 'rowsToInsert' number of rows into the table
*/
- public static void loadSchema(com.ibm.db2.jcc.DB2Connection conn,int rowsToInsert,PrintWriter pw) {
+ public static void loadSchema(Connection conn,int rowsToInsert,PrintWriter pw) {
int insertsRemaining = rowsToInsert;
PreparedStatement ps=null;
Modified: incubator/derby/code/trunk/java/demo/nserverdemo/SimpleNetworkClientSample.java
Url: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/nserverdemo/SimpleNetworkClientSample.java?view=diff&rev=126495&p1=incubator/derby/code/trunk/java/demo/nserverdemo/SimpleNetworkClientSample.java&r1=126494&p2=incubator/derby/code/trunk/java/demo/nserverdemo/SimpleNetworkClientSample.java&r2=126495
==============================================================================
--- incubator/derby/code/trunk/java/demo/nserverdemo/SimpleNetworkClientSample.java (original)
+++ incubator/derby/code/trunk/java/demo/nserverdemo/SimpleNetworkClientSample.java Wed Jan 26 02:27:56 2005
@@ -7,6 +7,7 @@
*/
import java.sql.*;
+import java.lang.reflect.*;
import javax.sql.DataSource;
import java.util.Properties;
import java.io.BufferedReader;
@@ -49,9 +50,10 @@
private static int NETWORKSERVER_PORT=1527;
/**
- * DB2 JDBC UNIVERSAL DRIVER class name
+ * DB2 JDBC UNIVERSAL DRIVER class names
*/
private static final String DB2_JDBC_UNIVERSAL_DRIVER = "com.ibm.db2.jcc.DB2Driver";
+ private static final String DB2_JCC_DS = "com.ibm.db2.jcc.DB2SimpleDataSource";
/**
* This URL is used to connect to Derby Network Server using the DriverManager.
@@ -138,27 +140,42 @@
* @throws Exception if there is any error
*/
public static javax.sql.DataSource getClientDataSource(String database, String user, String
- password) throws SQLException
+ password) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException
{
-
- com.ibm.db2.jcc.DB2SimpleDataSource ds = new com.ibm.db2.jcc.DB2SimpleDataSource();
+ Class nsDataSource = Class.forName(DB2_JCC_DS);
+ DataSource ds = (DataSource) nsDataSource.newInstance();
// can also include Derby URL attributes along with the database name
- ds.setDatabaseName(database);
-
- if (user != null)
- ds.setUser(user);
- if (password != null)
- ds.setPassword(password);
-
+ Class[] methodParams = new Class[] {String.class};
+ Method dbname = nsDataSource.getMethod("setDatabaseName", methodParams);
+ Object[] args = new Object[] {database};
+ dbname.invoke(ds, args);
+
+ if (user != null) {
+ Method setuser = nsDataSource.getMethod("setUser", methodParams);
+ args = new Object[] {user};
+ setuser.invoke(ds, args);
+ }
+ if (password != null) {
+ Method setpw = nsDataSource.getMethod("setPassword", methodParams);
+ args = new Object[] {password};
+ setpw.invoke(ds, args);
+ }
// host on which network server is running
- ds.setServerName("localhost");
+ Method servername = nsDataSource.getMethod("setServerName", methodParams);
+ args = new Object[] {"localhost"};
+ servername.invoke(ds, args);
// port on which Network Server is listening
- ds.setPortNumber(1527);
+ methodParams = new Class[] {int.class};
+ Method portnumber = nsDataSource.getMethod("setPortNumber", methodParams);
+ args = new Object[] {new Integer(1527)};
+ portnumber.invoke(ds, args);
// driver type must be 4 to access Derby Network Server
- ds.setDriverType(4);
+ Method drivertype = nsDataSource.getMethod("setDriverType", methodParams);
+ args = new Object[] {new Integer(4)};
+ drivertype.invoke(ds, args);
return ds;
@@ -193,7 +210,7 @@
properties.setProperty("password","scape");
// Get database connection using the JCC client via DriverManager api
- Connection conn = (com.ibm.db2.jcc.DB2Connection) DriverManager.getConnection(CS_NS_DBURL, properties);
+ Connection conn = DriverManager.getConnection(CS_NS_DBURL,properties);
return conn;
}