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;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货