1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

My datas are not displyed in mysql

Discussion in 'MySQL Forums' started by kamilia, Oct 22, 2016.

  1. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    Hi, everyone,

    I'm writing a program java in order to insert datas in mysql,the insertion is executed successfully, but when i check the insertion in Mysql, it writes that there is 3 or four rows in the total,like this:

    [​IMG] Affichage des lignes 0 - 4 (total de 5, Traitement en 0.0156 secondes.)

    that means the datas are inserted but when i execute the commnd select, the count of rows is displayed and the table too, but there is any data inside, it's empty, like this

    upload_2016-10-22_18-58-7.png

    i have searched to find the probleme, but i haven't found anything.

    Thanks for your help.
     
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,601
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Did you commit the changes?
     
  3. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    <code>about which changes do you speak?</code>
     
  4. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,601
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    The inserts.

    Post EXACTLY what you did to insert this data and see if it exists in the table.
     
  5. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    i don't know if my problem is clear, i've used a program java to connect into my sql;
    this is the code

    public class Connection {

    public static void main(String[] args) throws SQLException {


    String url="jdbc:mysql://localhost:3306/";
    String user="root";
    String pwd="kamilia";
    String db="masteril";
    java.sql.Connection con;
    con=DriverManager.getConnection(url+db, user, pwd);
    System.out.println("connection etablie");
    Statement t=con.createStatement();
    String query="insert into etudiant (matricule,nom, prenom) values('555','rrrr','eeeeee');";
    int etat = t.executeUpdate(query);
    if(etat==1)
    System.out.println("insertion effectuée");
    else
    System.out.println("insertion echouée");
    }



    }
     
  6. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    when i insert using the interface mysql, it's ok, but when i use the code above , i didn't found any data, and these datas don't exist in the table.

    NB: i havent'n made any contraint of primary key or not null or index in the table.
     
  7. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,601
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    The java calls do not automatically commit so the inserts are done and when the connection terminates the changes are lost. You need to add a commit to your java code; also please do NOT post passwords, even if they are in your code, as someone may figure out where your server is and be able to login and do harm to your database.
     
  8. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    it works when i put this in a class,
    but when i use ObjectInPutStream, it doesn't work;I get this exception:

    Exception in thread "main" java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.io_ObjectInputStream$PeekInputStream.read(Unknown Source)
    at java.io_ObjectInputStream$PeekInputStream.readFully(Unknown Source)
    at java.io_ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
    at java.io_ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io_ObjectInputStream.<init>(Unknown Source)
    at Tp02.C1.main(C1.java:36)

    lin 36 corresponds at this line in my code:
    i1=new ObjectInputStream(s.getInputStream());
     
  9. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,601
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Try this:

    String url="jdbc:mysql://localhost:3306/";
    String user="root";
    String pwd="kamilia";
    String db="masteril";
    java.sql.Connection con;
    con=DriverManager.getConnection(url+db, user, pwd);
    System.out.println("connection etablie");
    Statement t=con.createStatement();
    String query="insert into etudiant (matricule,nom, prenom) values('555','rrrr','eeeeee');";
    int etat = t.executeUpdate(query);
    if(etat==1)
    System.out.println("insertion effectuée");
    con.commit;
    else
    System.out.println("insertion echouée");
    }
     
  10. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
     
  11. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    the same thing, i get this exception :

    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
    at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1544)
    at Tp02.C3.inserer(C3.java:35)

    the line 35 correponds at: con.commit()
     
  12. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,601
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
  13. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    the same thing, i get this exception :

    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
    at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1544)
    at Tp02.C3.inserer(C3.java:35)

    the line 35 correponds at: con.commit()
     
  14. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,601
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Did you modify the code example provided to access YOUR database?
     
  15. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    i'll read it,
    I hope that I'll find a solution, thanks.
     
  16. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    no,just I've added con.commit();
    and when I remove it, I haven't any exception but no insertion too.
     
  17. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,601
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    You should REALLY use the example in the link and modify it to connect to your mysql database and see if it works.
     
  18. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    I use it but the problem isn't resolved,

    the message of (" insertion efectuée")is displayed ; but the datas are empty in mysql.
     
  19. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,601
    Likes Received:
    364
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    You may need to upgrade your version of java.
     
  20. kamilia

    kamilia Active Member

    Messages:
    21
    Likes Received:
    2
    Trophy Points:
    90
    Location:
    algiers
    I have eclipse luna 4.4.1 and mysql 5.7 ;
    you think really that is a problem.