不知道对不对,你和数据库的连接应该是由ejb容器来管理的吧。
解决方案 »
- spring mvc HttpSession存取数据时候是否需要考虑多线程安全问题
- 如何在跨域后保存session
- java 图片处理
- 如何用hibernate连接不同的数据库?
- 怎样获得HTML 的属性名?用JAVA代码写出来
- 求:hibernate-Extension,Middlegen-hibernate,junit
- Hibernate需要每天重启一道的奇怪问题,请大虾指点!
- JSP如何通过JNDI连接数据库 ?
- 请问那里有关于jbuilder的使用教程下载?
- ssh2使用aop后属性注入失败
- AXIS做web service,出现错误~
- 如何在tomcat中运行servlet程序???请教各位大哥哥!!先谢了!!!
就是执行
ps=con.prepareStatement("select ID from STUDENT where ID=?");
时报错
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@127.0.0.1:1521:SAMPLE</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>system</user-name>
<password>manager</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
</local-tx-datasource>
</datasources>
不知道joss配置数据源除了配置这一文件还配置哪些??
CMP时我也就配置这个文件,能用
我刚做了一个jboss+mysql的bmp实现,测试成功。
我用的是jboss+eclipse+oracle,你用的是什么?
代码:
public String ejbFindByPrimaryKey(String key) throws FinderException {
Connection con= null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con=getConnection();
ps=con.prepareStatement("select* from DB where SID=?");
ps.setString(1,key);
rs=ps.executeQuery();
System.out.println("successful");
}catch (Exception e) {
e.printStackTrace();
}finally{
try{
if(rs!=null){rs.close();}
if(ps!=null){rs.close();}
if(con!=null){rs.close();}
}catch(Exception ignore){
ignore.printStackTrace();
}
}
return key;
}
public Connection getConnection()throws Exception{
try{
Context ctx=new InitialContext();
javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/OracleDS");
return ds.getConnection();
}catch(Exception e)
{
System.out.println("Coudn't get datasource");
e.printStackTrace();
throw e;
}
}
ejb-jar.xml:
........
<entity >
<description><![CDATA[<!-- begin-user-doc --> You can insert your documentation for '<em><b>BmpbookBean</b></em>'.]]></description> <ejb-name>Bmpbook</ejb-name> <home>com.test.BmpbookHome</home>
<remote>com.test.Bmpbook</remote>
<local-home>com.test.BmpbookLocalHome</local-home>
<local>com.test.BmpbookLocal</local> <ejb-class>com.test.BmpbookBMP</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<resource-ref>
<res-ref-name>OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
........oralce-ds.xml内容如上。
望能帮帮我,谢谢
如果可以的话,把你测试通过的代码和配置文件发一份给我,好吗?
非常感谢