You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Renan Meneses de Andrade Franca <re...@yahoo.com.br> on 2007/09/24 03:14:30 UTC

Trouble: Connecting Derby with cdc.

Derby onli suporte DataSource method to get connect with a cdc program. But Hoe can i use the DataSource to get connection with a local database????????? please... i really need HELP!




      Flickr agora em português. Você clica, todo mundo vê.
http://www.flickr.com.br/

Re: Trouble: Connecting Derby with cdc.

Posted by John Embretsen <Jo...@Sun.COM>.
Renan Meneses de Andrade Franca wrote:
> Derby onli suporte DataSource method to get connect with a cdc program. 
> But Hoe can i use the DataSource to get connection with a local 
> database????????? please... i really need HELP!


Did you take a look at the SimpleApp demo included with Derby? It's in the 
demo/programs/simple/ directory in  your Derby installation. You can also view 
the source here: 
http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/simple/SimpleApp.java?view=markup

A relevant section is included below.

 From SimpleApp.java:


/* 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);
  }



-- 
John