Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: [HELP]Bugs of Java or Wrong Code?

  1. #1
    Junior Member
    Join Date
    May 2013
    Location
    Indonesia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question [HELP]Bugs of Java or Wrong Code?

    Dear All,
    What this is bugs of Java or me not to understand java programming, this my piece code :
    String kode = txtKode.getText();
            String nama = inputNama.getText();
            String keterangan = inputKeterangan.getText();
     
            try {
                Connection c = KoneksiMySql.getKoneksi();
                String sql = "UPDATE UNIT SET NAMA=?, KETERANGAN=?, WKT_INPUT=now() WHERE KODE=?";
                PreparedStatement p = c.prepareStatement(sql);
     
                p.setString(1, nama);
                p.setString(2, keterangan);
                p.setString(3, kode);
     
                p.executeUpdate();
                p.close();
                JOptionPane.showMessageDialog(null, "Data Berubah",
                        "Pemberitahuan", JOptionPane.INFORMATION_MESSAGE);
            } catch(SQLException e) {
                System.out.println("Error : " + e);
                JOptionPane.showMessageDialog(null, "Proses Rubah Unit Gagal",
                        "Pesan Error", JOptionPane.ERROR_MESSAGE);        
            }finally {
    	    inputNama.setText(null);
    	    inputKeterangan.setText(null);
                btnTambah.setEnable(true);
                btnHapus.setEnabled(false);
                btnRubah.setEnabled(false);
                inputNama.requestFocus();
            }

    JOptionPane is Show and no error appears but data in database does not change, and code in block finally not executed.
    i'm use jInternalFrame, first run Only 'Add Button, Search Button' enable and other button are disable, then when 'Search Button' is clicked and open other jInternalFrame and get data form database, 'Add button' Disable and 'Delete Button, Change Button' are Enable. that my piece code on Change Button ActionPerformed.

    Please it's support.
    Thanks,
    Best & Regrads.


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    491
    Thanks
    8
    Thanked 47 Times in 45 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?


  3. #3
    Junior Member
    Join Date
    May 2013
    Location
    Indonesia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    Quote Originally Posted by Darryl.Burke View Post
    ya, I posted on a few forums to get the answer. because sometimes if just post on one forum, I did not get the answer of my problem.

  4. #4
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    Hello.
    Which message of JOptionPane is being shown? The one in try block or the one in catch block?
    Can you print the connection obj to check if it is not null?

    Syed.

  5. #5
    Junior Member
    Join Date
    May 2013
    Location
    Indonesia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    Quote Originally Posted by syedbhai View Post
    Hello.
    Which message of JOptionPane is being shown? The one in try block or the one in catch block?
    Can you print the connection obj to check if it is not null?

    Syed.
    of course JOptionPane in try block, not the catch block, and there is no SQLException e errors that appear. its database connection class certainly is not null. I made a connection class in use by the whole project and checked connections at starup program, if the connection fails then the program will be closed. Another class no problem for Insert, Update and Delete using the connection class. This class includes previously no problem, this problem appeared after I use SetEnable() Method on the JButton, latter i will be upload the code.

  6. #6
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    I see.
    Whatever query you are executing can you try that at the sql prompt. If there is no change in the table then the problem is with the query. Either such record does not exist or some other reason.
    You said finally didn't execute. Can you put one JOptionPane.showMessageDialog() at the end of the finally block and check if the message appears?
    If it appears then finally block gets executed but you don't see the gui effects you are doing.
    Based on your answer I can suggest what to do next.

    Thanks,
    Syed.

  7. #7
    Junior Member
    Join Date
    May 2013
    Location
    Indonesia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    Quote Originally Posted by syedbhai View Post
    I see.
    Whatever query you are executing can you try that at the sql prompt. If there is no change in the table then the problem is with the query. Either such record does not exist or some other reason.
    You said finally didn't execute. Can you put one JOptionPane.showMessageDialog() at the end of the finally block and check if the message appears?
    If it appears then finally block gets executed but you don't see the gui effects you are doing.
    Based on your answer I can suggest what to do next.

    Thanks,
    Syed.
    sql query run properly, the data in the database was changed according to query. & already me try in phpMyAdmin query run properly. strange problem appears after I use Method SetEnable(false) on jButton, at the jInternalFrame first opened. & do Method SetEnable(true) after Table in jDialog retrieve data from the database and get selected row to field in jInternalFrame . yes i think the problem is located in the GUI, if there are specific rules to use the method SetEnable() on jButton?

    thanks,
    Best & Regrads.

  8. #8
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    Hello.
    If you want you can just mail me your code.
    I will try to fix it and reply back with the working code.

    Thanks,
    Syed.

  9. #9
    Junior Member
    Join Date
    May 2013
    Location
    Indonesia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    Quote Originally Posted by syedbhai View Post
    Hello.
    If you want you can just mail me your code.
    I will try to fix it and reply back with the working code.

    Thanks,
    Syed.
    ok.. thanks before.

  10. #10
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    Hello vikar,
    Your code is just fine.
    If you go to your Unit class and line numbered 265 you typed table name 'unit' in uppercase when it is expected to be in lowercase.

    Thanks,
    Syed.

  11. #11
    Junior Member
    Join Date
    May 2013
    Location
    Indonesia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [HELP]Bugs of Java or Wrong Code?

    Quote Originally Posted by syedbhai View Post
    Hello vikar,
    Your code is just fine.
    If you go to your Unit class and line numbered 265 you typed table name 'unit' in uppercase when it is expected to be in lowercase.

    Thanks,
    Syed.
    ok, i will check again. But in Insert Data menu i use uppercase 'INSERT INTO UNIT' run well, no problem found.
    Note : I've tried to change the 'UNIT' to lowercase, but the data in the database remains unchanged.[COLOR="Silver"]

    --- Update ---

    Thanks for the support, i have solve my problem. The problem it's located in Instance of jInternalFrame.
    I Love Java ^_^.[COLOR="Silver"]

Similar Threads

  1. What's wrong with my java code?
    By mjmz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 17th, 2012, 10:06 PM
  2. Replies: 10
    Last Post: April 5th, 2011, 09:09 AM
  3. Code bugs
    By heptix in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 30th, 2010, 03:32 AM
  4. [SOLVED] what is wrong for the java code
    By chuikingman in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 11th, 2010, 01:00 AM
  5. Replies: 1
    Last Post: May 8th, 2009, 08:55 AM

Tags for this Thread