SHARE
TWEET

Untitled

a guest Jun 17th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Conectate {
  2. private String driver ="com.mysql.jdbc.Driver";
  3. private String cadenaConexion ="jdbc:mysql://127.0.0.1/Blog";
  4. private String pass = "";
  5. private String usuario = "root";
  6. public Connection con;
  7.  
  8. public Conectate(String[][] listaEmpresaA) {
  9.     try {
  10.         Class.forName(driver);
  11.         con = DriverManager.getConnection(cadenaConexion, usuario, pass);
  12.         System.out.println("┬íConectado!");
  13.  
  14.  
  15.         //CREAMOS LA TABLA
  16.         Statement st = con.createStatement();
  17.  
  18.  
  19.         st.executeUpdate("CREATE TABLE IF NOT EXISTS Xbox_One (id INT AUTO_INCREMENT, "
  20.                 + "PRIMARY KEY(id), Juego VARCHAR(500), URL VARCHAR (200), Lanzamiento VARCHAR (50), Descripcion TEXT(5000),"
  21.                 + "Pegi VARCHAR(10), Descripcion_Pegi VARCHAR (200), nota FLOAT(10,1),"
  22.                 + "USA VARCHAR (100), USA_Gold VARCHAR (100), USA_sin_Gold VARCHAR (100), USA_EA VARCHAR (100),"
  23.                 + "ARG VARCHAR (100), ARG_Gold VARCHAR (100), ARG_sin_Gold VARCHAR (100), ARG_EA VARCHAR (100),"
  24.                 + "AUS VARCHAR (100), AUS_Gold VARCHAR (100), AUS_sin_Gold VARCHAR (100), AUS_EA VARCHAR (100),"
  25.                 + "BRA VARCHAR (100), BRA_Gold VARCHAR (100), BRA_sin_Gold VARCHAR (100), BRA_EA VARCHAR (100),"
  26.                 + "CAN VARCHAR (100), CAN_Gold VARCHAR (100), CAN_sin_Gold VARCHAR (100), CAN_EA VARCHAR (100),"
  27.                 + "SIN VARCHAR (100), SIN_Gold VARCHAR (100), SIN_sin_Gold VARCHAR (100), SIN_EA VARCHAR (100),"
  28.                 + "ESP VARCHAR (100), ESP_Gold VARCHAR (100), ESP_sin_Gold VARCHAR (100), ESP_EA VARCHAR (100),"
  29.                 + "HK VARCHAR (100), HK_Gold VARCHAR (100), HK_sin_Gold VARCHAR (100), HK_EA VARCHAR (100),"
  30.                 + "MEX VARCHAR (100), MEX_Gold VARCHAR (100), MEX_sin_Gold VARCHAR (100), MEX_EA VARCHAR (100),"
  31.                 + "COL VARCHAR (100), COL_Gold VARCHAR (100), COL_sin_Gold VARCHAR (100), COL_EA VARCHAR (100),"
  32.                 + "HUN VARCHAR (100), HUN_Gold VARCHAR (100), HUN_sin_Gold VARCHAR (100), HUN_EA VARCHAR (100),"
  33.                 + "SUD VARCHAR (100), SUD_Gold VARCHAR (100), SUD_sin_Gold VARCHAR (100), SUD_EA VARCHAR (100),"
  34.                 + "RUS VARCHAR (100), RUS_Gold VARCHAR (100), RUS_sin_Gold VARCHAR (100), RUS_EA VARCHAR (100),"
  35.                 + "CHI VARCHAR (100), CHI_Gold VARCHAR (100), CHI_sin_Gold VARCHAR (100), CHI_EA VARCHAR (100),"
  36.                 + "IND VARCHAR (100), IND_Gold VARCHAR (100), IND_sin_Gold VARCHAR (100), IND_EA VARCHAR (100),"
  37.                 + "JP VARCHAR (100), JP_Gold VARCHAR (100), JP_sin_Gold VARCHAR (100), JP_EA VARCHAR (100),"
  38.                 + "KOR VARCHAR (100), KOR_Gold VARCHAR (100), KOR_sin_Gold VARCHAR (100), KOR_EA VARCHAR (100),"
  39.                 + "TAI VARCHAR (100), TAI_Gold VARCHAR (100), TAI_sin_Gold VARCHAR (100), TAI_EA VARCHAR (100),"
  40.                 + "UK VARCHAR (100), UK_Gold VARCHAR (100), UK_sin_Gold VARCHAR (100), UK_EA VARCHAR (100))"
  41.                 );
  42.  
  43.         System.out.println( "Tabla creada!");
  44.  
  45.  
  46.         PreparedStatement ps = con.prepareStatement("INSERT INTO           Xbox_One (Juego, URL, Publicado, Lanzamiento, Descripcion, Pegi, Descripcion_Pegi, nota, "
  47.                                 + "USA, USA_Gold, USA_sin_Gold, USA_EA,"
  48.                                 + "ARG, ARG_Gold, ARG_sin_Gold, ARG_EA,"
  49.                                 + "AUS, AUS_Gold, AUS_sin_Gold, AUS_EA,"
  50.                                 + "BRA, BRA_Gold, BRA_sin_Gold, BRA_EA,"
  51.                                 + "CAN, CAN_Gold, CAN_sin_Gold, CAN_EA,"
  52.                                 + "SIN, SIN_Gold, SIN_sin_Gold, SIN_EA,"
  53.                                 + "ESP, ESP_Gold, ESP_sin_Gold, ESP_EA,"
  54.                                 + "HK, HK_Gold, HK_sin_Gold, HK_EA,"
  55.                                 + "MEX, MEX_Gold, MEX_sin_Gold, MEX_EA,"
  56.                                 + "COL, COL_Gold, COL_sin_Gold, COL_EA,"
  57.                                 + "HUN, HUN_Gold, HUN_sin_Gold, HUN_EA,"
  58.                                 + "SUD, SUD_Gold, SUD_sin_Gold, SUD_EA,"
  59.                                 + "RUS, RUS_Gold, RUS_sin_Gold, RUS_EA,"
  60.                                 + "CHI, CHI_Gold, CHI_sin_Gold, CHI_EA,"
  61.                                 + "CHINA, CHINA_Gold, CHINA_sin_Gold, CHINA_EA,"
  62.                                 + "IND, IND_Gold, IND_sin_Gold, IND_EA,"
  63.                                 + "JP, JP_Gold, JP_sin_Gold, JP_EA,"
  64.                                 + "KOR, KOR_Gold, KOR_sin_Gold, KOR_EA,"
  65.                                 + "TAI, TAI_Gold, TAI_sin_Gold, TAI_EA,"
  66.                                 + "UK, UK_Gold, UK_sin_Gold, UK_EA)"
  67.                                 + ") VALUES (?,?,?,?,?,?,?,?"
  68.                                 + ",?,?,?,?"
  69.      + ",?,?,?,?"
  70.      + ",?,?,?,?"
  71.      + ",?,?,?,?"
  72.      + ",?,?,?,?"
  73.      + ",?,?,?,?"
  74.      + ",?,?,?,?"
  75.      + ",?,?,?,?"
  76.      + ",?,?,?,?"
  77.      + ",?,?,?,?"
  78.      + ",?,?,?,?"
  79.      + ",?,?,?,?"
  80.      + ",?,?,?,?"
  81.      + ",?,?,?,?"
  82.      + ",?,?,?,?"
  83.      + ",?,?,?,?"
  84.      + ",?,?,?,?"
  85.      + ",?,?,?,?"
  86.      + ",?,?,?,?"
  87.      + ",?,?,?,?"
  88.                                 + ")");
  89.  
  90.  
  91.         for(String[] array : listaEmpresaA){
  92.             for(int i = 0; i < 95; ++i){ //Careful to an             arrayoutofbounds exception, but every parameter MUST BE SET
  93.                 ps.setString(i+2, array[i]); //Can't be null, if so, must use setNull(i+1);
  94.             }
  95.         ps.executeUpdate();
  96.         }
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.     } catch (Exception e) {
  105.         JOptionPane.showMessageDialog(null, "No se ha podido establecer la conexi├│n con la DB");
  106.     }
  107.  
  108. }
  109.  
  110. public String ConvertirObjectToString(Object Obj) {
  111. String Str="";
  112. if(Obj!=null){
  113.     Str = Obj.toString();
  114. }
  115. return Str;
  116. }
  117.  
  118.  
  119. }
  120.      
  121. for(String[] array : listaEmpresaA){
  122.         for(int i = 0; i < 88; i++){
  123.             // Careful to avoid ArrayIndexOutOfBoundsException
  124.             if (array[i]!=null || i >= array.length){
  125.                 ps.setString(i+1, array[i]);
  126.             } else {
  127.                 ps.setNull(i+1);
  128.             }
  129.         //Can't be null, if so, must use setNull(i+1);
  130.         }
  131.     ps.executeUpdate();
  132.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top