Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 46004 invoked from network); 9 Nov 2007 22:26:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Nov 2007 22:26:31 -0000 Received: (qmail 99075 invoked by uid 500); 9 Nov 2007 22:26:19 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 99042 invoked by uid 500); 9 Nov 2007 22:26:19 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 99031 invoked by uid 99); 9 Nov 2007 22:26:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Nov 2007 14:26:19 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Nov 2007 22:26:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 535231A9832; Fri, 9 Nov 2007 14:26:02 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r593673 - in /db/derby/code/trunk/java/demo/simple: SimpleApp.java example.html Date: Fri, 09 Nov 2007 22:26:01 -0000 To: derby-commits@db.apache.org From: myrnavl@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071109222602.535231A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: myrnavl Date: Fri Nov 9 14:26:01 2007 New Revision: 593673 URL: http://svn.apache.org/viewvc?rev=593673&view=rev Log: DERBY-3187 - backing out changes made with DERBY-2216 to support SimpleApp with j2ME as the implementation causes trouble with client and does not work properly with all JVMs. patch contributed by John H. Embretsen. Modified: db/derby/code/trunk/java/demo/simple/SimpleApp.java db/derby/code/trunk/java/demo/simple/example.html Modified: db/derby/code/trunk/java/demo/simple/SimpleApp.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/simple/SimpleApp.java?rev=593673&r1=593672&r2=593673&view=diff ============================================================================== --- db/derby/code/trunk/java/demo/simple/SimpleApp.java (original) +++ db/derby/code/trunk/java/demo/simple/SimpleApp.java Fri Nov 9 14:26:01 2007 @@ -55,9 +55,6 @@ public String framework = "embedded"; public String driver = "org.apache.derby.jdbc.EmbeddedDriver"; public String protocol = "jdbc:derby:"; - - public String username = "user1"; - public String password = "user1"; public static void main(String[] args) { @@ -69,14 +66,6 @@ /* parse the arguments to determine which framework is desired*/ parseArguments(args); - /* check for J2ME specification - J2ME must use a DataSource further on */ - String javaspec = System.getProperty( "java.specification.name" ); - boolean java2me = false; - if( javaspec.indexOf( "J2ME" ) > -1 ) - { - java2me = true; - } - System.out.println("SimpleApp starting in " + framework + " mode."); try @@ -85,56 +74,26 @@ The driver is installed by loading its class. In an embedded environment, this will start up Derby, since it is not already running. */ - org.apache.derby.jdbc.EmbeddedSimpleDataSource ds = null; + Class.forName(driver).newInstance(); + System.out.println("Loaded the appropriate driver."); + Connection conn = null; Properties props = new Properties(); - props.put("user", username); - props.put("password", password); + props.put("user", "user1"); + props.put("password", "user1"); - /* If we are using a J2ME jvm, we need to use a DataSource, otherwise - * we can use java.sql.DriverManager to get the connection, or - * a Datasource. This example program uses a DataSource with J2ME - * but uses DriverManager otherwise. - * If we were to use a DataSource for J2SE, we could use - * the org.apache.derby.jdbc.EmbeddedDataSource, rather than the - * org.apache.derby.jdbc.EmbeddedSimpleDataSource we need to use for J2ME. - */ - - if( java2me ) - { - /* - The connection specifies create in the DataSource settings for - the database to be created. To remove the database, - remove the directory derbyDB and its contents. - The directory derbyDB will be created under - the directory that the system property - derby.system.home points to, or the current - directory if derby.system.home is not set. - */ - - ds = new org.apache.derby.jdbc.EmbeddedSimpleDataSource(); - ds.setDatabaseName("derbyDB"); - ds.setCreateDatabase("create"); - conn = ds.getConnection(username, password); - } - else - { - /* - The connection specifies create=true in the url to cause - the database to be created. To remove the database, - remove the directory derbyDB and its contents. - The directory derbyDB will be created under - the directory that the system property - derby.system.home points to, or the current - directory if derby.system.home is not set. - */ - - Class.forName(driver).newInstance(); - System.out.println("Loaded the appropriate driver."); - - conn = DriverManager.getConnection(protocol + + /* + The connection specifies create=true to cause + the database to be created. To remove the database, + remove the directory derbyDB and its contents. + The directory derbyDB will be created under + the directory that the system property + derby.system.home points to, or the current + directory if derby.system.home is not set. + */ + conn = DriverManager.getConnection(protocol + "derbyDB;create=true", props); - } + System.out.println("Connected to and created database derbyDB"); conn.setAutoCommit(false); @@ -224,32 +183,13 @@ if (framework.equals("embedded")) { - /* again, with J2ME, we need to use a datasource to get the connection */ - if( java2me ) + try { - try - { - ds.setShutdownDatabase( "shutdown" ); - conn = ds.getConnection(username, password); - } - catch (SQLException se) - { - if( se.getErrorCode() == 45000 ) - { - gotSQLExc = true; - } - } + DriverManager.getConnection("jdbc:derby:;shutdown=true"); } - else - { - try - { - DriverManager.getConnection("jdbc:derby:;shutdown=true"); - } - catch (SQLException se) - { - gotSQLExc = true; - } + catch (SQLException se) + { + gotSQLExc = true; } if (!gotSQLExc) @@ -308,4 +248,4 @@ } } } -} \ No newline at end of file +} Modified: db/derby/code/trunk/java/demo/simple/example.html URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/simple/example.html?rev=593673&r1=593672&r2=593673&view=diff ============================================================================== --- db/derby/code/trunk/java/demo/simple/example.html (original) +++ db/derby/code/trunk/java/demo/simple/example.html Fri Nov 9 14:26:01 2007 @@ -18,7 +18,7 @@ - + Simple JDBC Application @@ -69,7 +69,6 @@ This example program is a very minimal JDBC application. JDBC is the primary API for interacting with Apache Derby. This program:

  • runs in either embedded mode (the default) or as a client in a server environment, depending on the arguments passed to the program. -
  • runs in J2ME or J2SE Java Virtual Machines.
  • starts up the Derby engine, if running in embedded mode
  • connects to the Derby Network Server, if running in client mode
  • creates and connects to a database @@ -82,7 +81,7 @@
  • shuts down Derby, if running in embedded mode

- In embedded mode, the application starts up an instance of Derby within the current Java Virtual Machine and shuts down the instance before it completes. For a J2ME Java Virtual Machine an appropriate DataSource is used, otherwise, the java.sql.Driver mechanism is used. No network access is involved. Only one application can access a database at a time. + In embedded mode, the application starts up an instance of Derby within the current Java Virtual Machine and shuts down the instance before it completes. No network access is involved. Only one application can access a database at a time.

In a server environment, the application demonstrates the use of the Derby network client or the IBM DB2 JDBC Universal Driver by connecting to the Network Server and running the demo. Note that the client drivers allow multiple instances of the application to run at the same time. However, the SQL operations performed by this demo will cause failures when multiple simultaneous instances of the application are run. Use of a client driver to connect to the Network Server in this application is intended only to demonstrate this type of connection. The SimpleApp demo is not suited for simultaneous executions because it creates and drops the table on which it operates.