db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r593673 - in /db/derby/code/trunk/java/demo/simple: SimpleApp.java example.html
Date Fri, 09 Nov 2007 22:26:01 GMT
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 @@
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<meta name="LASTUPDATED" content="07/18/01 06:12:42">
+<meta name="LASTUPDATED" content="2007-11-08 09:18:20 UTC">
 <link rel="StyleSheet" href="../csfull.css" type="text/css" media="screen">
 <title>Simple JDBC Application</title>
 
@@ -69,7 +69,6 @@
   <a name="820012"> </a>This example program is a very minimal JDBC application.
JDBC is the primary API for interacting with Apache Derby. This program:
 </p><ul class="Normal">  
   <li class="Normal">runs in either embedded mode (the default) or as a client in a
server environment, depending on the arguments passed to the program.
-  <li class="Normal">runs in J2ME or J2SE Java Virtual Machines.
   <li class="Normal"><a name="817266"> </a>starts up the Derby engine,
if running in embedded mode
   <li class="Normal"><a name="817266"> </a>connects to the Derby Network
Server, if running in client mode
   <li class="Normal"><a name="817275"> </a>creates and connects to a database
@@ -82,7 +81,7 @@
   <li class="Normal"><a name="817282"> </a>shuts down Derby, if running
in embedded mode
 </ul>
 <p class="Body">
-  <a name="817267"> </a>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. 
+  <a name="817267"> </a>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. 
 </p>
 <p>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.
 </p>



Mime
View raw message