Here's pieces of a test program I wrote about a year ago when we were
looking at BMP - it's not great code, but it worked. This ran with Sybase
and Hypersonic; the Sybase data-sources.xml section is below (the
Hypersonic version was as-shipped with around 1.0). Hope this helps...
Kirk Yarina
/**
* update a row in the database
*/
private void
updateRow()
throws FinderException
{
// if ( ! this.isModified ) return;
String updateStatement =
"UPDATE address set "
+ "addr1 = ?,"
+ "addr2 = ?,"
+ "addr3 = ?,"
+ "city = ?,"
+ "state = ?,"
+ "zipcode = ?,"
+ "country = ? "
+ "where id = ?";
Connection con = null;
PreparedStatement ps = null;
try
{
con = this.getConnection();
ps = con.prepareStatement(updateStatement);
int ix = 1;
ps.setString(ix++,this.addr1);
ps.setString(ix++,this.addr2);
ps.setString(ix++,this.addr3);
ps.setString(ix++,this.city);
ps.setString(ix++,this.state);
ps.setString(ix++,this.zipcode);
ps.setString(ix++,this.country);
// where id = ?
ps.setLong(ix,this.id);
if (ps.executeUpdate() != 1)
{
throw new FinderException ("Store address.id "+this.id);
}
}
catch (SQLException se)
{
se.printStackTrace( System.err );
throw new EJBException( "updateRow "+se.getMessage() );
}
finally
{
try
{
if ( ps != null )
ps.close();
if ( con != null )
con.close();
}
catch (Exception e) {}; // ignore SQLExceptions...
}
}
private Connection
getConnection()
{
String dsName = "jdbc/DefaultEJBDS"; // Pooled connections
InitialContext initialContext = null;
try {
initialContext = new InitialContext();
}
catch ( Exception ex )
{
System.err.println( "-- Getting Initial Context --" );
ex.printStackTrace( System.err );
throw new EJBException
("getting address initialContext, " + ex.getMessage() );
}
try {
DataSource ds =
(DataSource) initialContext.lookup( dsName );
return ds.getConnection();
}
catch ( Exception ex )
{
System.err.println
( "-- looking up DataSource '" + dsName + "' --" );
ex.printStackTrace( System.err );
throw new EJBException
( "looking up dsName '"
+ dsName + "', " + ex.getMessage() );
}
-------------
<data-source
name="Default data-source"
class="com.evermind.sql.ConnectionDataSource"
location="jdbc/DefaultDS"
pooled-location="jdbc/DefaultPooledDS"
xa-location="jdbc/xa/DefaultXADS"
ejb-location="jdbc/DefaultEJBDS"
url="jdbc:sybase:Tds:some.server.com:4100/somedb"
connection-driver="com.sybase.jdbc2.jdbc.SybDriver"
username="*****"
password="*****"
schema="database-schemas/sybase.xml"
/>
At 11:19 AM 3/16/01 -0800, you wrote:
>Thanks for the advice, still not working.
>Getting a different Error when trying the EJB data source. ANy ideas?
>
>Exception in thread "main" java.lang.NullPointerException
> at com.evermind.sql.OrionPooledDataSource.ej(JAX)
> at com.evermind.sql.OrionPooledDataSource.d8(JAX)
> at com.evermind.sql.ak.eo(JAX)
> at com.evermind.sql.ak.ep(JAX)
> at com.evermind.sql.ap.createStatement(JAX)
> at Test.main(Test.java:33)
>
>
>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, March 15, 2001 11:14 PM
>To: Orion-Interest
>Subject: Re: No suitable driver exception
>
>
>Try:
>
> DataSource ds = (DataSource)ctx.lookup("jdbc/OracleDS"); instead of
> DataSource ds = (DataSource)ctx.lookup("jdbc/OracleCoreDS");
>
>regards
>/Theis.