Connection and PreparedStatement
- From: francan00@xxxxxxxxx
- Date: Tue, 13 Nov 2007 16:38:20 -0800
Is this a good way to insert and update into an Oracle database or is
there anything I can improve?
public class Sports
{
private Connection connection;
public Sports() {
connection = new DatabaseConnection().getConnection();
}
public void Inserter(BeanMain objref) throws SQLException
{
if(connection != null)
{
PreparedStatement stat =
connection.prepareStatement("Insert into FranchiseTable (team,
manager) values (?,?)");
stat.setString(1, objref.getTeam());
stat.setString(2, objref.getManager());
stat.executeUpdate();
stat.close();
}
}
public void Updater(BeanMain objref) throw SQLException
{
if(connection != null)
{
PreparedStatement stat = connection.prepareStatement("update
PlayersTable set Id = ? where name LIKE ? ");
stat.setInt(1, objref.getId());
stat.setString(2, objref.getName());
stat.executeUpdate():
stat.close();
}
}
public void DatabasesUpdIns(BeanMain objref)
{
try
{
Inserter(objref);
Updaterer(objref);
}
catch(SQLException ex)
{
System.out.println(ex);
}
finally
{
connection.close();
}
}
.
- Follow-Ups:
- Re: Connection and PreparedStatement
- From: Ruud de Koter
- Re: Connection and PreparedStatement
- From: Lew
- Re: Connection and PreparedStatement
- Prev by Date: error handling in ant
- Next by Date: Re: Connection and PreparedStatement
- Previous by thread: error handling in ant
- Next by thread: Re: Connection and PreparedStatement
- Index(es):
Relevant Pages
|
|