import javax.annotation.Resource;
import javax.annotation.sql.DataSourceDefinition;
import javax.annotation.sql.DataSourceDefinitions;
import java.sql.*;
import javax.sql.*;
@javax.ejb.Stateless(mappedName="Hello")
@javax.ejb.Remote(Hello.class)
@DataSourceDefinitions(
@DataSourceDefinition(name = "myresourceb",
className = "oracle.jdbc.pool.OracleDataSource",
url = "jdbc:oracle:thin:@192.168.161.159:1521:ORCL",
user = "sadfsfs",
portNumber = 1521,
databaseName="ORCL",
serverName = "192.168.161.159",
password = "asfasfsf",
properties={"url=jdbc:oracle:thin:@192.168.161.159:1521:ORCL","serverName=192.168.161.159",
"user=sadfsfs","password=asfasfsf","portNumber=1521",
"databaseName=ORCL"}))
public class HelloImpl implements Hello {
@Resource(lookup="java:comp/env/myresourceb")
DataSource dataSource;
Connection con = null;
PreparedStatement pstm = null;
ResultSet rest = null;
@Override
public String test() {
StringBuffer sb = new StringBuffer();
try{
con = dataSource.getConnection();
pstm = con.prepareStatement("select * from user_tables");
rest = pstm.executeQuery();
while(rest.next()){
String str = rest.getString(1);
sb.append(str);
System.out.println(str);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if( null != rest){
rest.close();
rest = null;
}
if( null != pstm ){
pstm.close();
pstm = null;
}
if( null != con ){
con.close();
con = null;
}
}catch(Exception e){
e.printStackTrace();
}
}
return sb.toString();
}
}
ejb3.1 lite tmp
最新推荐文章于 2013-04-01 20:15:00 发布