Advertisement
Guest User

Untitled

a guest
Mar 10th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. public class main {
  2.  
  3. public static void main(String[] args) throws Exception {
  4.  
  5. sql test = new sql();
  6. String[][] test2 = test.getDb();
  7. System.out.print(test2[0][0]);
  8. }
  9.  
  10. import java.sql.DriverManager;
  11. import java.sql.PreparedStatement;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.util.ArrayList;
  15.  
  16. import javax.swing.JLabel;
  17. import javax.swing.JTextField;
  18.  
  19. import com.mysql.jdbc.Statement;
  20.  
  21. public class sql {
  22.  
  23. java.sql.Connection con = null;
  24. PreparedStatement pst = null;
  25. ResultSet rs = null;
  26. String url = "jdbc:mysql://localhost:8889/deliveryEarn";
  27. String user = "root";
  28. String password = "root";
  29.  
  30. ArrayList<String> sqlCol1 = new ArrayList<String>();
  31. ArrayList<String> sqlCol2 = new ArrayList<String>();
  32. ArrayList<String> sqlCol3 = new ArrayList<String>();
  33. ArrayList<String> sqlCol4 = new ArrayList<String>();
  34. ArrayList<String> sqlCol5 = new ArrayList<String>();
  35. ArrayList<String> sqlCol6 = new ArrayList<String>();
  36. ArrayList<String> sqlCol7 = new ArrayList<String>();
  37. String sqlArray[][] = new String[7][7];
  38.  
  39. public sql() {
  40. }
  41.  
  42. public String[][] getDb() {
  43. try {
  44. con = DriverManager.getConnection(url, user, password);
  45. pst = con.prepareStatement("select * from incomeCalc");
  46. rs = pst.executeQuery();
  47.  
  48. while (rs.next()) {
  49.  
  50. sqlCol1.add(rs.getString(1));
  51. int i1=0;
  52. for(String s: sqlCol1){
  53. sqlArray[i1++][0] = s;
  54. }
  55.  
  56. sqlCol2.add(rs.getString(2));
  57. int i2=0;
  58. for(String s: sqlCol2){
  59. sqlArray[i2++][1] = s;
  60. }
  61.  
  62. sqlCol3.add(rs.getString(3));
  63. int i3=0;
  64. for(String s: sqlCol3){
  65. sqlArray[i3++][2] = s;
  66. }
  67.  
  68. sqlCol4.add(rs.getString(4));
  69. int i4=0;
  70. for(String s: sqlCol4){
  71. sqlArray[i4++][3] = s;
  72. }
  73.  
  74. sqlCol5.add(rs.getString(5));
  75. int i5=0;
  76. for(String s: sqlCol5){
  77. sqlArray[i5++][4] = s;
  78. }
  79.  
  80. sqlCol6.add(rs.getString(6));
  81. int i6=0;
  82. for(String s: sqlCol6){
  83. sqlArray[i6++][5] = s;
  84. }
  85. sqlCol7.add(rs.getString(7));
  86. int i7=0;
  87. for(String s: sqlCol7){
  88. sqlArray[i7++][6] = s;
  89. }
  90. }
  91. }
  92.  
  93. catch( Exception E ) {
  94. System.out.println( E.getMessage() );
  95. }
  96. return sqlArray;
  97. }
  98. }
  99.  
  100. System.out.print(test2[0][0]);
  101.  
  102. public class Income {
  103. // Column decelerations...
  104.  
  105. private long id;
  106. private int tips;
  107. private int hours;
  108. private int gas;
  109. private double hourly;
  110. private double other;
  111. private double other2;
  112.  
  113. public int getGas() {
  114. return gas;
  115. }
  116.  
  117. public double getHourly() {
  118. return hourly;
  119. }
  120.  
  121. public int getHours() {
  122. return hours;
  123. }
  124.  
  125. public long getId() {
  126. return id;
  127. }
  128.  
  129. public double getOther() {
  130. return other;
  131. }
  132.  
  133. public double getOther2() {
  134. return other2;
  135. }
  136.  
  137. public int getTips() {
  138. return tips;
  139. }
  140.  
  141. public void setGas(int gas) {
  142. this.gas = gas;
  143. }
  144.  
  145. public void setHourly(double hourly) {
  146. this.hourly = hourly;
  147. }
  148.  
  149. public void setHours(int hours) {
  150. this.hours = hours;
  151. }
  152.  
  153. public void setId(long id) {
  154. this.id = id;
  155. }
  156.  
  157. public void setOther(double other) {
  158. this.other = other;
  159. }
  160.  
  161. public void setOther2(double other2) {
  162. this.other2 = other2;
  163. }
  164.  
  165. public void setTips(int tips) {
  166. this.tips = tips;
  167. }
  168. }
  169.  
  170. public Income[] getIncome() {
  171.  
  172. // Call database...
  173.  
  174. List<Income> data = new ArrayList<Income>(25);
  175.  
  176. while (rs.next()) {
  177.  
  178. Income income = new Income();
  179.  
  180. income.setID(rs.getInt(1)));
  181. income.setTips(rs.getInt(2)));
  182. income.setHours(rs.getInt(3)));
  183. income.setGas(rs.getInt(4)));
  184. income.setHourly(rs.getDouble(5)));
  185. income.setOther(rs.getDouble(6)));
  186. income.setOther2(rs.getDouble(7)));
  187.  
  188. data.add(income);
  189.  
  190. }
  191.  
  192. return data.toArray(new Income[data.size()]);
  193.  
  194. }
  195.  
  196. sql test = new sql();
  197. Income[] incomes = test.getIncome();
  198.  
  199. System.out.println(incomes[0].getID());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement