You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.2 KiB

7 years ago
  1. package hsfulda.de;
  2. import java.sql.ResultSet;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. public class FedResultSet implements FedResultSetInterface {
  6. private FedStatement fedStatement;
  7. private HashMap<Integer, ResultSet> resultSets = new HashMap<Integer, ResultSet>();
  8. public FedResultSet(FedStatement fedStatement) {
  9. this.fedStatement = fedStatement;
  10. }
  11. public FedStatement getStatement() {
  12. return fedStatement;
  13. }
  14. public boolean next() throws FedException {
  15. try {
  16. for (Object i : resultSets.keySet()) {
  17. if (resultSets.get(i).next())
  18. return true;
  19. }
  20. } catch (SQLException sqlException) {
  21. throw new FedException(sqlException);
  22. }
  23. return false;
  24. }
  25. public String getString(int columnIndex) throws FedException {
  26. try {
  27. for (Object i : resultSets.keySet()) {
  28. if (!resultSets.get(i).isAfterLast())
  29. return resultSets.get(i).getString(columnIndex);
  30. }
  31. } catch (SQLException sqlException) {
  32. throw new FedException(sqlException);
  33. }
  34. return null;
  35. }
  36. public int getInt(int columnIndex) throws FedException {
  37. try {
  38. for (Object i : resultSets.keySet()) {
  39. if (!resultSets.get(i).isAfterLast())
  40. return resultSets.get(i).getInt(columnIndex);
  41. }
  42. } catch (SQLException sqlException) {
  43. throw new FedException(sqlException);
  44. }
  45. return 0;
  46. }
  47. public void close() throws FedException {
  48. try {
  49. for (Object i : resultSets.keySet()) {
  50. resultSets.get(i).close();
  51. }
  52. } catch (SQLException sqlException) {
  53. throw new FedException(sqlException);
  54. }
  55. }
  56. public int getColumnCount() throws FedException {
  57. try {
  58. return resultSets.get(0).getMetaData().getColumnCount();
  59. } catch (SQLException sqlException) {
  60. throw new FedException(sqlException);
  61. }
  62. }
  63. public String getColumnName(int index) throws FedException {
  64. try {
  65. return resultSets.get(0).getMetaData().getColumnName(index);
  66. } catch (SQLException sqlException) {
  67. throw new FedException(sqlException);
  68. }
  69. }
  70. public int getColumnType(int index) throws FedException {
  71. try {
  72. return resultSets.get(0).getMetaData().getColumnType(index);
  73. } catch (SQLException sqlException) {
  74. throw new FedException(sqlException);
  75. }
  76. }
  77. public void setResultSet(int index, ResultSet resultSet) {
  78. resultSets.put(index, resultSet);
  79. }
  80. }