请熟悉castor JDO的朋友帮个忙!!!!!!!

jd29323 2003-02-12 05:28:57
我刚刚下在了castor JDO 0.9.4.3,我想写个用JDO的小的程序学习它
我用的WEBLOGIC7,请问怎么配置可以让JDO能用
(我不想在TOMCAT下测试)

谢谢
...全文
59 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
andyzhu98 2003-06-25
  • 打赏
  • 举报
回复
gz
pentax 2003-06-06
  • 打赏
  • 举报
回复
这个问题也好办啊,你可以ctx.rebind(key, val);val可以是Database啊,key也不一定是"java:comp/env/jdo/mydb"。这样就可以lookup了。
treeClimber 2003-06-06
  • 打赏
  • 举报
回复
空口无凭,我想最关键的是 db = (Database) ctx.lookup( "java:comp/env/jdo/mydb" );
jdni怎么能造型为(Database?)
pentax 2003-02-14
  • 打赏
  • 举报
回复
可以参考:http://castor.exolab.org
pentax 2003-02-14
  • 打赏
  • 举报
回复
JDO数据库配置指定了去获取数据库服务器的连接,映射了Java类和Table表之间的关系;Castor不能用JDBC-ODBC桥,Access不被支持。

获取一个数据库连接有下列三种方式:
one:作为一个JDBC 2.0的驱动URL;
two:作为JDBC2.0的数据源;
three:作为一个通过JNDI寻找的数据源;
当JDO作为J2EE应用时推荐第三种用法。允许服务器管理连接池和分布式事务;

类映射被包含在一个外部映射文件中,允许一个数据库数据库配置文件中包含多个配置文件,或者两个数据库配置文件共享一个映射文件,但是两个数据库决不要去用重叠的映射文件,一个数据库推荐只用一个数据库文件。
作为客户端(JDBC应用):
JDO jdo;
Database db;

// Define the JDO object
jdo = new JDO();
jdo.setDatabaseName( "mydb" );
jdo.setConfiguration( "database.xml" );
jdo.setClassLoader( getClass().getClassLoader() );

// Obtain a new database
db = jdo.getDatabase();
// Begin a transaction
db.begin();
// Do something
. . .
// Commit the transaction, close database
db.commit();
db.close();
J2EE应用:
InitialContext ctx;
UserTransaction ut;
Database db;

// Lookup databse in JNDI
ctx = new InitialContext();
db = (Database) ctx.lookup( "java:comp/env/jdo/mydb" );

// Begin a transaction
ut = (UserTransaction) ctx.lookup( "java:comp/UserTransaction" );
ut.begin();
// Do something
. . .
// Commit the transaction, close database
ut.commit();
db.close();


要写一个datebase.xml和tablename.xml两个文件,里面:
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor JDO Configuration DTD Version 1.0//EN"
"http://castor.exolab.org/jdo-conf.dtd">
The following configuration file uses an Oracle 8 thin JDBC driver and three mapping files:

<database name="ebiz" engine="oracle">
<driver class-name="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@machine:post:SID">
<param name="user" value="scott" />
<param name="password" value="tiger" />
</driver>
<mapping href="product.xml" />
<mapping href="orders.xml" />
<mapping href="customers.xml" />
</database>


The following configuration file uses a connection obtained from the J2EE application server and a single mapping file:

<database name="ebiz" engine="oracle">
<jndi name="java:comp/env/jdbc/mydb" />
<mapping href="product.xml" />
</database>

products.xml是一个表的描述:
多个表也可以整合在一个xml文件中,xml文件名随便,只要关联统一就行了

Here is an example of a mapping file and the corresponding Java object and DDL for the databse table.

The following is an example Java object:

package myapp;

public class Product
{
private int _id;

private String _name;

private float _price;

private ProductGroup _group;


public int getId()
...

public void setId( int anId )
...

public String getName()
...

public void setName( String aName )
...

public float getPrice()
...

public void setPrice( float aPrice )
...

public ProductGroup getProductGroup()
...

public void setProductGroup( ProductGroup aProductGroup )
...
}



The following is the relational database table:

create table prod
(
id int not null,
name varchar(200) not null,
price numeric(18,2) not null,
group_id int not null
);



The following is the mapping file for the example Java object:

<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping>

<class name="myapp.Product" identity="id">

<map-to table="prod" />

<field name="id" type="integer">
<sql name="id" type="integer" />
</field>

<field name="name" type="string">
<sql name="name" type="char" />
</field>

<field name="price" type="float">
<sql name="price" type="numeric" />
</field>

<field name="group" type="myapp.ProductGroup" >
<sql name="group_id" />
</field>

</class>
</maping>

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧