Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class main {
- public static void main(String[] args) throws Exception {
- sql test = new sql();
- String[][] test2 = test.getDb();
- System.out.print(test2[0][0]);
- }
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import com.mysql.jdbc.Statement;
- public class sql {
- java.sql.Connection con = null;
- PreparedStatement pst = null;
- ResultSet rs = null;
- String url = "jdbc:mysql://localhost:8889/deliveryEarn";
- String user = "root";
- String password = "root";
- ArrayList<String> sqlCol1 = new ArrayList<String>();
- ArrayList<String> sqlCol2 = new ArrayList<String>();
- ArrayList<String> sqlCol3 = new ArrayList<String>();
- ArrayList<String> sqlCol4 = new ArrayList<String>();
- ArrayList<String> sqlCol5 = new ArrayList<String>();
- ArrayList<String> sqlCol6 = new ArrayList<String>();
- ArrayList<String> sqlCol7 = new ArrayList<String>();
- String sqlArray[][] = new String[7][7];
- public sql() {
- }
- public String[][] getDb() {
- try {
- con = DriverManager.getConnection(url, user, password);
- pst = con.prepareStatement("select * from incomeCalc");
- rs = pst.executeQuery();
- while (rs.next()) {
- sqlCol1.add(rs.getString(1));
- int i1=0;
- for(String s: sqlCol1){
- sqlArray[i1++][0] = s;
- }
- sqlCol2.add(rs.getString(2));
- int i2=0;
- for(String s: sqlCol2){
- sqlArray[i2++][1] = s;
- }
- sqlCol3.add(rs.getString(3));
- int i3=0;
- for(String s: sqlCol3){
- sqlArray[i3++][2] = s;
- }
- sqlCol4.add(rs.getString(4));
- int i4=0;
- for(String s: sqlCol4){
- sqlArray[i4++][3] = s;
- }
- sqlCol5.add(rs.getString(5));
- int i5=0;
- for(String s: sqlCol5){
- sqlArray[i5++][4] = s;
- }
- sqlCol6.add(rs.getString(6));
- int i6=0;
- for(String s: sqlCol6){
- sqlArray[i6++][5] = s;
- }
- sqlCol7.add(rs.getString(7));
- int i7=0;
- for(String s: sqlCol7){
- sqlArray[i7++][6] = s;
- }
- }
- }
- catch( Exception E ) {
- System.out.println( E.getMessage() );
- }
- return sqlArray;
- }
- }
- System.out.print(test2[0][0]);
- public class Income {
- // Column decelerations...
- private long id;
- private int tips;
- private int hours;
- private int gas;
- private double hourly;
- private double other;
- private double other2;
- public int getGas() {
- return gas;
- }
- public double getHourly() {
- return hourly;
- }
- public int getHours() {
- return hours;
- }
- public long getId() {
- return id;
- }
- public double getOther() {
- return other;
- }
- public double getOther2() {
- return other2;
- }
- public int getTips() {
- return tips;
- }
- public void setGas(int gas) {
- this.gas = gas;
- }
- public void setHourly(double hourly) {
- this.hourly = hourly;
- }
- public void setHours(int hours) {
- this.hours = hours;
- }
- public void setId(long id) {
- this.id = id;
- }
- public void setOther(double other) {
- this.other = other;
- }
- public void setOther2(double other2) {
- this.other2 = other2;
- }
- public void setTips(int tips) {
- this.tips = tips;
- }
- }
- public Income[] getIncome() {
- // Call database...
- List<Income> data = new ArrayList<Income>(25);
- while (rs.next()) {
- Income income = new Income();
- income.setID(rs.getInt(1)));
- income.setTips(rs.getInt(2)));
- income.setHours(rs.getInt(3)));
- income.setGas(rs.getInt(4)));
- income.setHourly(rs.getDouble(5)));
- income.setOther(rs.getDouble(6)));
- income.setOther2(rs.getDouble(7)));
- data.add(income);
- }
- return data.toArray(new Income[data.size()]);
- }
- sql test = new sql();
- Income[] incomes = test.getIncome();
- System.out.println(incomes[0].getID());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement