Advertisement
Guest User

Add SQL

a guest
Apr 21st, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. public Object[][] getTable4(String vi, String br, String mo, String ye, String mi, String pr, String co ) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
  2.     {
  3.         System.out.println("vin" + vi);
  4.         System.out.println("brand" + br);
  5.         System.out.println("model" + mo);
  6.         System.out.println("year" + ye);
  7.         System.out.println("mileage" + mi);
  8.         System.out.println("price" + pr);
  9.         System.out.println("color" + co);
  10.        
  11.         Class.forName("com.mysql.jdbc.Driver").newInstance();
  12.         String s1 = "jdbc:mysql://localhost:3306/carmax";
  13.         Connection connection = DriverManager.getConnection(s1, "root", "Laughable65!");
  14.         Statement statement = connection.createStatement();
  15.        
  16.         if (vi.equals("") && br.equals("") && mo.equals("") && ye.equals("") && mi.equals("") && pr.equals("") && co.equals(""))
  17.         {
  18.             vi = "%";          
  19.             br = "%";
  20.             mo = "%";
  21.             co = "%";
  22.             ye = "%";
  23.             pr = "%";
  24.             mi = "%";
  25.         }
  26.         /*else
  27.         {
  28.             JOptionPane.showMessageDialog(null, "Please fill in all fields.", "Warning", JOptionPane.WARNING_MESSAGE);
  29.         }*/
  30.  
  31.         statement.executeUpdate("insert into cars(vin,brand,model,year,mileage,price,color) values('" + vi + "', '" + br + "', '" + mo + "', '" + ye + "', '" + mi + "', '" + pr + "', '" + co +"')");
  32.         ResultSet rs = statement.executeQuery("select * from cars");
  33.        
  34.         Object[][] data = new Object[100][7];
  35.         int count=0;
  36.         while(rs.next())
  37.         {
  38.             data[count][0] = rs.getString("vin");
  39.             data[count][1] = rs.getString("brand");
  40.             data[count][2] = rs.getString("model");
  41.             data[count][3] = rs.getInt("year");
  42.             data[count][4] = rs.getInt("mileage");
  43.             data[count][5] = rs.getInt("price");
  44.             data[count][6] = rs.getString("color");
  45.             count++;
  46.         }
  47.        
  48.         connection.close();
  49.         return data;
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement