当前位置: 技术问答>java相关
求一小段代码!
来源: 互联网 发布时间:2017-04-20
本文导语: SESSIONBEAN中,要连到ORACLE,实现查询EMP表记录,请给出源码!谢谢! | private Connection getConnection() { try { Context initial = new InitialContext(); DataSource dataSource = ...
SESSIONBEAN中,要连到ORACLE,实现查询EMP表记录,请给出源码!谢谢!
|
private Connection getConnection()
{
try
{
Context initial = new InitialContext();
DataSource dataSource =
(DataSource) initial.lookup("LocalOracleDS");
return dataSource.getConnection();
}
catch (javax.naming.NamingException ne)
{
ne.printStackTrace();
throw new EJBException(ne);
}
catch (java.sql.SQLException sqle)
{
sqle.printStackTrace();
throw new EJBException(sqle);
}
}
public Collection ejbFindByOwnerName(String ownerName) throws FinderException {
Connection con = null;
try
{
con = getConnection();
PreparedStatement statement = // Primary key info
con.prepareStatement("SELECT SPORT, NICKNAME " +
"FROM SPORTSTEAMS WHERE OWNERNAME = ? ");
statement.setString(1, ownerName);
ResultSet resultSet = statement.executeQuery();
LinkedList queryMatches = new LinkedList();
while (resultSet.next()) {
SportTeamPK pk = new SportTeamPK(resultSet.getString(1),
resultSet.getString(2));
queryMatches.add(pk);
}
resultSet.close();
statement.close();
return queryMatches;
}
{
try
{
Context initial = new InitialContext();
DataSource dataSource =
(DataSource) initial.lookup("LocalOracleDS");
return dataSource.getConnection();
}
catch (javax.naming.NamingException ne)
{
ne.printStackTrace();
throw new EJBException(ne);
}
catch (java.sql.SQLException sqle)
{
sqle.printStackTrace();
throw new EJBException(sqle);
}
}
public Collection ejbFindByOwnerName(String ownerName) throws FinderException {
Connection con = null;
try
{
con = getConnection();
PreparedStatement statement = // Primary key info
con.prepareStatement("SELECT SPORT, NICKNAME " +
"FROM SPORTSTEAMS WHERE OWNERNAME = ? ");
statement.setString(1, ownerName);
ResultSet resultSet = statement.executeQuery();
LinkedList queryMatches = new LinkedList();
while (resultSet.next()) {
SportTeamPK pk = new SportTeamPK(resultSet.getString(1),
resultSet.getString(2));
queryMatches.add(pk);
}
resultSet.close();
statement.close();
return queryMatches;
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。