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 2 of 2

Thread: i try to use jtable to show contents from mysql directly without mouseclicking but it's error

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default i try to use jtable to show contents from mysql directly without mouseclicking but it's error

    i want to make adding into mysql database and then when i click adds, jtable show those data automatically. but it seem to get error at display part, it shows " Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - illegal start of expression" and jtable do not show the added data but in mysql, data is properly kept.

    private void jtPropertyChange(java.beans.PropertyChangeEvent evt) {
    DefaultTableModel model = (DefaultTableModel) jt.getModel();
    try {
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection(url, user, password);
    String sql = "SELECT * FROM `companya`";
    st = con.prepareStatement(sql);
    rs = st.executeQuery(sql);
    while(rs.next()){
    String id = rs.getString("code");
    String name = rs.getString("name");
    String position = rs.getString("position");
    String salary = rs.getString("salary");
    model.addRow(new Object[]{id,name,position,salary});
    }
    }catch(Exception e){
    System.out.println("error");}
    }

    the adding part seems to be fine


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: i try to use jtable to show contents from mysql directly without mouseclicking but it's error

    This code does not compile. Figure out what your compiler error is before trying to run it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. converson from mysql database into xml directly using java
    By abhi1402 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 9th, 2013, 12:37 AM
  2. jdbc integration with Gui to show user information retrieved from mysql
    By harem_najat in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 22nd, 2013, 07:25 PM
  3. data won't show up in jtable
    By takamine in forum Object Oriented Programming
    Replies: 10
    Last Post: February 6th, 2013, 08:18 AM
  4. Problem with JTable and MySQL
    By mija in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 17th, 2012, 03:29 PM
  5. I am trying to show database contents in the browser through servlets
    By abhiM in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 12th, 2011, 02:08 AM