java.sql.SQLException: Table not found: STUDENT in statement [select ID from STUDENT where ID=?]
14:07:39,642 INFO [STDOUT] at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
14:07:39,642 INFO [STDOUT] at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
14:07:39,642 INFO [STDOUT] at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
14:07:39,642 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:374)
14:07:39,642 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:217)
14:07:39,642 INFO [STDOUT] at com.test.BmpbookBean.ejbFindByPrimaryKey(BmpbookBean.java:102)
14:07:39,642 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:07:39,652 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
14:07:39,652 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
14:07:39,652 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:324)
14:07:39,652 INFO [STDOUT] at org.jboss.ejb.plugins.BMPPersistenceManager.callFinderMethod(BMPPersistenceManager.java:560)
14:07:39,652 INFO [STDOUT] at org.jboss.ejb.plugins.BMPPersistenceManager.findEntity(BMPPersistenceManager.java:289)
14:07:39,652 INFO [STDOUT] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.findEntity(CachedConnectionInterceptor.java:302)
14:07:39,652 INFO [STDOUT] at org.jboss.ejb.EntityContainer.findSingleObject(EntityContainer.java:1043)
14:07:39,652 INFO [STDOUT] at org.jboss.ejb.EntityContainer.find(EntityContainer.java:679)
14:07:39,652 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
14:07:39,692 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
14:07:39,692 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
14:07:39,692 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:324)
14:07:39,692 INFO [STDOUT] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeH
………………
代码如下:
public String ejbFindByPrimaryKey(String key) throws FinderException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// Class.forName(“oracle.jdbc.driver.OracleDriver”);
//String url=”jdbc:oracle:thin:@localhost:1521:SAMPLE”;
con=getConnection();
//con=DriverManager.getConnection(url,”system”,”manager”);
System.out.println(“connection”);
ps=con.prepareStatement(“select ID from STUDENT where ID=?”);
ps.setString(1,key);
rs=ps.executeQuery();
System.out.println(“successful”);
}catch (Exception e) {
System.out.println(e);
System.out.println(“null point”);
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
……..
<resource-ref>
<res-ref-name>OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
如果用class.forName()来访问就没问题,不知为何??