Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 6th, 2012  |  syntax: None  |  size: 1.28 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package corbaServer.dao;
  2.  
  3. import java.sql.SQLException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import corbaServer.RaceDO;
  7. import java.sql.*;
  8.  
  9. public class CorbaRaceServerDAO implements ICorbaRaceServerDAO {
  10.  
  11.         Connection connection;
  12.     static final String controller = "org.sqlite.JDBC";
  13.        
  14.         public void connect() throws SQLException
  15.         {
  16.                 try
  17.                 {
  18.                         Class.forName(controller);
  19.                 }
  20.                 catch (ClassNotFoundException e)
  21.                 {
  22.                         e.printStackTrace();
  23.                 }
  24.                 connection = DriverManager.getConnection("jdbc:sqlite:db/corba-db/gipuzkoaraces.db");
  25.         }
  26.  
  27.         public List<RaceDO> getRaces() throws SQLException
  28.         {
  29.                 List<RaceDO> races = null;
  30.                 try
  31.                 {
  32.                         races = new ArrayList<RaceDO>();
  33.                         Statement statement = this.connection.createStatement();  
  34.                 ResultSet rs = statement.executeQuery("SELECT * FROM races;");  
  35.                 while (rs.next())
  36.                 {  
  37.                         RaceDO race = new RaceDO(rs.getString("name"),rs.getFloat("distance"),rs.getString("date"),rs.getInt("places"));
  38.                         races.add(race);
  39.                  }  
  40.                 rs.close();
  41.             statement.close();
  42.                 }
  43.                 catch(SQLException e)
  44.                 {
  45.                         e.printStackTrace();
  46.                 }
  47.                 return races;
  48.         }
  49.  
  50.         public void disconnect() throws SQLException
  51.         {
  52.        connection.close();  
  53.         }
  54.        
  55.        
  56. }