Results 1 to 14 of 14
  1. #1
    JetLagFox is offline Member
    Join Date
    Jan 2017
    Posts
    21
    Rep Power
    0

    Default Problems when creating a table in phpmyadmin from java

    Hi everyone,

    I am having problems to create a table from java. To be more specific, I am able to create te table, but if I want to edit any information I am shown an error message:

    Problems when creating a table in phpmyadmin from java-captura_de_pantalla_2017_02_28_a_las_22_38_00.png

    I am also having with the column "Juego_asociado", it's a column that its empty because I want to full it manually, but when I want to introduce information I am given the following error:

    Problems when creating a table in phpmyadmin from java-captura_de_pantalla_2017_02_28_a_las_22_37_40.png

    The code I am using in java to create the table and full it with the data:


    PHP Code:
    public class Conectate {
        private String driver ="com.mysql.jdbc.Driver";
        private String cadenaConexion ="jdbc:mysql://localhost/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) {
        public Conectate(ArrayList<Item> games) {    
            
            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 info_XboxOne (id INT AUTO_INCREMENT, PRIMARY KEY(id), "
                        + "Juego_vinculado VARCHAR(500), Juego VARCHAR(500), Tipologia VARCHAR (500), Pertenece VARCHAR (500), "
                        + "Nota VARCHAR (10), Descripcion_Ingles TEXT(4000), Descripcion_Castellano TEXT(4000), Pegi VARCHAR(10), Descripcion_Pegi VARCHAR(200),"
                        + "Lanzamiento VARCHAR (50))");
    
                System.out.println( "Tabla creada!");
                
                
                for (Item game : games) {
                    String titulo = game.getName();
    
                    boolean isInsert;
                    try (PreparedStatement ps = con.prepareStatement("SELECT * FROM info_XboxOne WHERE juego = ?")) {
                        ps.setString(1, titulo);
    
                        try (ResultSet rs = ps.executeQuery()) {
                            isInsert = !rs.next();
                        }
                    }
    
                    if (isInsert) { //si se cumple esta condicción significa que el juego no está incluido, con lo que lo metemos
                        try(PreparedStatement ps = con.prepareStatement("INSERT INTO info_XboxOne (Juego, Tipologia, Pertenece, "
                        + "Nota, Descripcion_Ingles, Descripcion_Castellano, Pegi, Descripcion_Pegi"
                        + ") VALUES (?,?,?,?,?,?,?,?)")) {
    
                            ps.setString(1,titulo);
                            ps.setString(2,game.getValues().get(Constants.TIPOLOGIA));
                            ps.setString(3,game.getValues().get(Constants.PERTENECE));                                            
                            ps.setString(4,game.getValues().get(Constants.NOTA));
                            ps.setString(5,game.getValues().get(Constants.DESCRIPCION_INGLES));
                            ps.setString(6,game.getValues().get(Constants.DESCRIPCION_CASTELLANO));
                            ps.setString(7,game.getValues().get(Constants.PEGI));
                            ps.setString(8,game.getValues().get(Constants.DESCRIPCION_PEGI));    
    
                            ps.executeUpdate();
                        }
                    } else {
                        String query = "UPDATE info_XboxOne SET Tipologia = ?, Pertenece = ?, "
                        + "Nota = ?, Descripcion_Ingles = ?, Descripcion_Castellano = ?, "
                        + "Pegi = ?, Descripcion_Pegi = ? WHERE juego = ?";
    
                        try (PreparedStatement ps = con.prepareStatement(query)) {
                            ps.setString(1,game.getValues().get(Constants.TIPOLOGIA));
                            ps.setString(2,game.getValues().get(Constants.PERTENECE));                                            
                            ps.setString(3,game.getValues().get(Constants.NOTA));
                            ps.setString(4,game.getValues().get(Constants.DESCRIPCION_INGLES));
                            ps.setString(5,game.getValues().get(Constants.DESCRIPCION_CASTELLANO));
                            ps.setString(6,game.getValues().get(Constants.PEGI));
                            ps.setString(7,game.getValues().get(Constants.DESCRIPCION_PEGI));
                            ps.setString(8,titulo);
    
                            ps.executeUpdate();
                        }
                    }           
    }
                          
        } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "No se ha podido establecer la conexión con la DB" + e);
                    e.printStackTrace();
                }
            
        }
        
        public String ConvertirObjectToString(Object Obj) {
        String Str="";
        if(Obj!=null){
            Str = Obj.toString();
        }
        return Str;
    }
    
        
    }

    Hope somebody could help me.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Problems when creating a table in phpmyadmin from java

    I'm not sure where things are going wrong.

    Does the above code work without errors?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    JetLagFox is offline Member
    Join Date
    Jan 2017
    Posts
    21
    Rep Power
    0

    Default Re: Problems when creating a table in phpmyadmin from java

    Yes, there are no errors. Everything seems to work fine.

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Problems when creating a table in phpmyadmin from java

    Seeing 'undefined' makes me think this is a JavaScript/phpmyadmin issue, since 'undefined' is a common value found in JavaScript. In the second screenshot the WHERE clause is indeed empty. You should try to verify your database with an external tool like Heidi or DBVisualiser to see if it's the database that's correpted in some way, or maybe it's a bug in phpmyadmin.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Problems when creating a table in phpmyadmin from java

    In these case my first thought is always "version mismatch"...:)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    JetLagFox is offline Member
    Join Date
    Jan 2017
    Posts
    21
    Rep Power
    0

    Default Re: Problems when creating a table in phpmyadmin from java

    Quote Originally Posted by SurfMan View Post
    Seeing 'undefined' makes me think this is a JavaScript/phpmyadmin issue, since 'undefined' is a common value found in JavaScript. In the second screenshot the WHERE clause is indeed empty. You should try to verify your database with an external tool like Heidi or DBVisualiser to see if it's the database that's correpted in some way, or maybe it's a bug in phpmyadmin.
    Heidi is another database like MySQL?

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Problems when creating a table in phpmyadmin from java

    Heidi is a database explorer tool: https://www.heidisql.com/
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  8. #8
    JetLagFox is offline Member
    Join Date
    Jan 2017
    Posts
    21
    Rep Power
    0

    Default Re: Problems when creating a table in phpmyadmin from java

    Quote Originally Posted by Tolls View Post
    In these case my first thought is always "version mismatch"...:)
    What does that mean?

    Quote Originally Posted by SurfMan View Post
    Heidi is a database explorer tool: https://www.heidisql.com/
    I have realized that I cannot use Heidi because I am using Mac.

  9. #9
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Problems when creating a table in phpmyadmin from java

    It looks as if SequelPro does the job: Sequel Pro
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  10. #10
    JetLagFox is offline Member
    Join Date
    Jan 2017
    Posts
    21
    Rep Power
    0

    Default Re: Problems when creating a table in phpmyadmin from java

    Quote Originally Posted by SurfMan View Post
    It looks as if SequelPro does the job: Sequel Pro
    I have created a partition in Mac to install Windows, and after installing HeidiSQL and importing the tables...the table it was giving me problems it works. I mean, the information is full and I can edit it, but It's not easy to understand how it works, I am accustomed to MySQL. I haven't proved yet if I run the java code it will créate the table without errors. I will try it now.

  11. #11
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Problems when creating a table in phpmyadmin from java

    Quote Originally Posted by JetLagFox View Post
    I have created a partition in Mac to install Windows, and after installing HeidiSQL and importing the tables...the table it was giving me problems it works. I mean, the information is full and I can edit it, but It's not easy to understand how it works, I am accustomed to MySQL. I haven't proved yet if I run the java code it will créate the table without errors. I will try it now.
    So, apparently it's not the table. Your issue is with phpmyadmin. Is that the latest version? You using any browserplugins that might interfere? Adblockers, privacytools, Greasemonkey?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  12. #12
    JetLagFox is offline Member
    Join Date
    Jan 2017
    Posts
    21
    Rep Power
    0

    Default Re: Problems when creating a table in phpmyadmin from java

    Yes I think, is the first time I have had problems with MySQL, but is also the first time I am using java to create a table. I have try the link you have passed me and in Sequel Pro everything is OK, I can even import the information. If I don't find the problem with MySQL I will have to use that program.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Problems when creating a table in phpmyadmin from java

    I would check the version of PHPMyAdmin first, and see if there's any issues with it when used against the version of MySQL you are using.
    That's what I meant by "version issue".

    Java would have complained if there had been an issue with the JDBC driver and the CREATE TABLE against the MySQL db.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Problems when creating a table in phpmyadmin from java

    If you're only using phpmyadmin to see what's in the database, you'd probably be better off with a tool like Sequel Pro. Less overhead too.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

Similar Threads

  1. Doubts with Excel and phpmyadmin
    By JetLagFox in forum New To Java
    Replies: 1
    Last Post: 01-16-2017, 04:41 PM
  2. Problems creating classic dos game snake in java
    By rmmohan in forum AWT / Swing
    Replies: 1
    Last Post: 01-05-2014, 07:13 PM
  3. jdbc connection with phpmyadmin
    By anand_fevi in forum JDBC
    Replies: 2
    Last Post: 05-19-2010, 01:45 PM
  4. Need help creating a table
    By Knizz in forum SWT / JFace
    Replies: 3
    Last Post: 07-18-2009, 03:46 AM
  5. regarding to creating table.....
    By daredavil82 in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 04:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •