public test(){
try {
// get the DataSource from JNDI
InitialContext initialContext = new InitialContext();
Object object = initialContext.lookup( "testDB");
dataSource = (DataSource) PortableRemoteObject.narrow( object, DataSource.class );
} catch( Throwable t ) {
t.printStackTrace();
throw new RuntimeException( "couldn't find DataSource '" + dataSourceName + "' in JNDI-registry : " + t.getMessage() );
}
}
try {
// get the DataSource from JNDI
InitialContext initialContext = new InitialContext();
Object object = initialContext.lookup( "testDB");
dataSource = (DataSource) PortableRemoteObject.narrow( object, DataSource.class );
} catch( Throwable t ) {
t.printStackTrace();
throw new RuntimeException( "couldn't find DataSource '" + dataSourceName + "' in JNDI-registry : " + t.getMessage() );
}
}
解决方案 »
- ibatis spring表关联插入
- 最近一执行MyEclipse的main()方法,程序老是自动关闭,求有经验的前辈指点~~
- jsp+Struts2+hibernate+spring 如何实现修改?
- 请求帮忙Struts1的问题
- 哪位仁兄又weblogic的中文教程
- ireport中的模糊查询
- 关于记录日志的超难度问题,相信只有超牛人才能回答了。
- 表示层 的架构 tapestry 和velocity 谁能说说 这两的比较?
- 关于struts中checkbox的用法.
- 新手求助,给你高分!!SOS!!!
- 在单机(无任何连接)上用weblogic做j2ee程序,遇到的奇怪问题?请朋友们帮忙?
- struts中选项菜单select中带有一个默认值的问题。
{
try {
// get the connection
connection = dataSource.getConnection(); // get the first free id
PreparedStatement stmt = connection.prepareStatement( selectStatement );
ResultSet resultSet = stmt.executeQuery();
resultSet.next();
firstIdOfBlock = resultSet.getLong( 1 );
stmt.close(); // add blockSize to the first free id
stmt = connection.prepareStatement( updateStatement );
stmt.setLong( 1, ( firstIdOfBlock + blockSize ) );
int nbrOfUpdatedRecords = stmt.executeUpdate();
stmt.close(); // there may only be one record in the table
if ( nbrOfUpdatedRecords != 1 ) {
throw new RuntimeException( "more then one record was updated by statement '" + updateStatement + "'" );
} } catch (SQLException e) {
context.setRollbackOnly();
if ( e.getMessage().indexOf( "Table not found" ) != -1 ) {
throw new SQLException( "Did you forget to create the database ? : SequenceSession-EJB couldn't create new block of id's : " + e.getMessage() );
} else {
throw new SQLException( "SequenceSession-EJB couldn't create new block of id's : " + e.getMessage() );
}
} catch (Throwable t) {
context.setRollbackOnly();
t.printStackTrace();
throw new RuntimeException( "SequenceSession-EJB couldn't create new block of id's : " + t.getMessage() );
} finally {
if ( connection != null ) {
try {
connection.close();
} catch (Throwable t ) {
t.printStackTrace();
System.out.println( "SequenceSession-EJB couldn't close connection while fetching a next block of database id's : " + t.getMessage() );
}
}
}}
Tomcat + Oracle + Linux 用JNDI的,谢谢!