Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Conectate {
- private String driver ="com.mysql.jdbc.Driver";
- private String cadenaConexion ="jdbc:mysql://127.0.0.1/XboxOne";
- private String pass = "";
- private String usuario = "root";
- public Connection con;
- public Conectate(Map<String, Map<String, Item>> gamesByCountry, Map<String, String> codesByTitle,Map<String, String> countries) {
- try {
- Class.forName(driver);
- con = DriverManager.getConnection(cadenaConexion, usuario, pass);
- System.out.println("¡Conectado!");
- //CREAMOS LA TABLA
- Statement st = con.createStatement();
- st.executeUpdate("CREATE TABLE IF NOT EXISTS Xbox_One (id INT AUTO_INCREMENT, "
- + "PRIMARY KEY(id), Juego VARCHAR(500), Tipologia VARCHAR (500), Pertenece VARCHAR (500), Lanzamiento VARCHAR (50)"
- + "nota FLOAT(10,1),"
- + "USA VARCHAR (100), USA_Gold VARCHAR (100), USA_sin_Gold VARCHAR (100), USA_EA VARCHAR (100),"
- );
- System.out.println( "Tabla creada!");
- PreparedStatement ps = con.prepareStatement("INSERT INTO Xbox_One (Juego, Tipologia, Pertenece, Lanzamiento, nota, "
- + "USA, USA_Gold, USA_sin_Gold, USA_EA,"
- + ") VALUES (?,?,?,?,?"
- + ",?,?,?,?"
- + ")");
- for (String titulo : codesByTitle.keySet()) {
- String code = codesByTitle.get(titulo);
- for (String country : countries.keySet()) {
- Item game = gamesByCountry.get(country).get(code);
- for(int i = 0; i < 9; ++i){ //
- ps.setString(i+1, titulo);
- ps.setString(i+2, game.getValues().get(Constants.TIPOLOGIA));
- ps.setString(i+3, game.getValues().get(Constants.PERTENECE));
- ps.setString(i+4, game.getValues().get(Constants.FECHA));
- ps.setString(i+5, game.getValues().get(Constants.NOTA));
- ps.setString(i+5, game.getValues().get(Constants.PRICE_NORMAL));
- ps.setString(i+5, game.getValues().get(Constants.PRICE_OFFER));
- ps.setString(i+5, game.getValues().get(Constants.PRICE_GOLD));
- ps.setString(i+5, game.getValues().get(Constants.PRICE_EA));
- }
- }
- ps.executeUpdate();
- }
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "No se ha podido establecer la conexión con la DB" + e);
- }
- }
- public String ConvertirObjectToString(Object Obj) {
- String Str="";
- if(Obj!=null){
- Str = Obj.toString();
- }
- return Str;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement