Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. public class Conectate {
  2. private String driver ="com.mysql.jdbc.Driver";
  3. private String cadenaConexion ="jdbc:mysql://127.0.0.1/XboxOne";
  4. private String pass = "";
  5. private String usuario = "root";
  6. public Connection con;
  7.  
  8. public Conectate(Map<String, Map<String, Item>> gamesByCountry, Map<String, String> codesByTitle,Map<String, String> countries) {
  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), Tipologia VARCHAR (500), Pertenece VARCHAR (500), Lanzamiento VARCHAR (50)"
  21. + "nota FLOAT(10,1),"
  22. + "USA VARCHAR (100), USA_Gold VARCHAR (100), USA_sin_Gold VARCHAR (100), USA_EA VARCHAR (100),"
  23. );
  24.  
  25.  
  26.  
  27.  
  28. System.out.println( "Tabla creada!");
  29.  
  30.  
  31. PreparedStatement ps = con.prepareStatement("INSERT INTO Xbox_One (Juego, Tipologia, Pertenece, Lanzamiento, nota, "
  32. + "USA, USA_Gold, USA_sin_Gold, USA_EA,"
  33. + ") VALUES (?,?,?,?,?"
  34. + ",?,?,?,?"
  35. + ")");
  36.  
  37.  
  38. for (String titulo : codesByTitle.keySet()) {
  39.  
  40. String code = codesByTitle.get(titulo);
  41. for (String country : countries.keySet()) {
  42. Item game = gamesByCountry.get(country).get(code);
  43. for(int i = 0; i < 9; ++i){ //
  44. ps.setString(i+1, titulo);
  45. ps.setString(i+2, game.getValues().get(Constants.TIPOLOGIA));
  46. ps.setString(i+3, game.getValues().get(Constants.PERTENECE));
  47. ps.setString(i+4, game.getValues().get(Constants.FECHA));
  48. ps.setString(i+5, game.getValues().get(Constants.NOTA));
  49. ps.setString(i+5, game.getValues().get(Constants.PRICE_NORMAL));
  50. ps.setString(i+5, game.getValues().get(Constants.PRICE_OFFER));
  51. ps.setString(i+5, game.getValues().get(Constants.PRICE_GOLD));
  52. ps.setString(i+5, game.getValues().get(Constants.PRICE_EA));
  53. }
  54. }
  55. ps.executeUpdate();
  56. }
  57.  
  58. } catch (Exception e) {
  59. JOptionPane.showMessageDialog(null, "No se ha podido establecer la conexión con la DB" + e);
  60. }
  61.  
  62. }
  63.  
  64. public String ConvertirObjectToString(Object Obj) {
  65. String Str="";
  66. if(Obj!=null){
  67. Str = Obj.toString();
  68. }
  69. return Str;
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement