0

I have created a script where I try to fetch data from a database to a jtable and when I click submit I store the data from the row into another database. I try to create a refresh button that stores the data but it isn't working.

I have tried to debug it, but I get an error or nothing happens. I have no clue why it happens when I try to add a row. Right now nothing happens and the row doesn't get added.

public void actionPerformed(ActionEvent arg0) {
        String myquery = "SELECT * FROM myTable t WHERE t.trade_no NOT IN (SELECT trade_no FROM newTable)";

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            final Connection con = DriverManager.getConnection(
                    "url", "user",
                    "password");

            preparedStatement = con.prepareStatement(myquery);
            rs = preparedStatement.executeQuery(myquery);
            rs.next();
            row[0] = rs.getString("Trade_Type").toString();
            row[0] = rs.getString("Trade_Type").toString();
            row[0] = rs.getString("Value_date").toString();
            row[0] = rs.getString("CCY_Sold").toString();
            row[0] = rs.getString("Amt_Sold").toString();
            row[0] = rs.getString("CCY_Bought").toString();
            row[0] = rs.getString("Amt_Bought").toString();
            row[0] = rs.getString("Rate").toString();
            row[0] = rs.getString("Cparty").toString();
            con.commit();
            con.close();
            model.addRow(row);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
theduck
  • 2,589
  • 13
  • 17
  • 23
  • This problem is not related to Swing. Don't add irrelevant tags. – Andrew Thompson Oct 13 '19 at 15:14
  • Check out how to [create a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Without all that commented code chances are, you see the issue anyway. – Curiosa Globunznik Oct 13 '19 at 15:37
  • I removed the comments and read your link you gave me and i still dont see why it doesnt add the next row – Nick Demetraides Oct 13 '19 at 16:00
  • infact no matter where i put addRow none of the numbers i put(as seen in system.out.print) get printed – Nick Demetraides Oct 13 '19 at 16:02
  • I didnt copy and pasted this i typed it i would have put the rest of the code but this website wouldnt allow me to put the rest of it because script was more than 30 000 and java.lang.NullPointerException – Nick Demetraides Oct 13 '19 at 16:40
  • Which error do you get? Call stack pls. "In fact no matter where i put them, no debug messages get printed". Chances are, your method doesen't get called at all. Pls check out [how to debug](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems?noredirect=1&lq=1) the thing (apart from writing debug messages). – Curiosa Globunznik Oct 13 '19 at 18:18
  • btw you swallow every exception, not a good idea. Better rethrow a RuntimeException if you want to spare yourself a [checked exception](https://www.geeksforgeeks.org/checked-vs-unchecked-exceptions-in-java/) in the method signature. – Curiosa Globunznik Oct 13 '19 at 18:20
  • okay well now did some fixing i dont get an error message instead when my row is added i dont get the values is there away i can show you a image of my table when i try to edit one in the question it doesnt allow me – Nick Demetraides Oct 13 '19 at 18:42
  • I don't want to do your work. I propose again, that you try do [debug it](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems?noredirect=1&lq=1). This way you can see step for step which data comes out where and goes where. It is an extremely useful skill that you can't avoid at all when you want to do this for a living. – Curiosa Globunznik Oct 13 '19 at 19:24
  • I have some questions about the code you posted. Is `row` an array of `String`? Why do you add each column from the [SQL] query to `row[0]`? `model` is the `TableModel`, right? But `TableModel` is an interface. What is the actual type for `model`? (Because `TableModel` does not declare a `addRow()` method.) – Abra Oct 14 '19 at 00:53
  • model is DefaultTableModel yes it gives me the option to add the row problem is when i try to add the row it doesnt give me different data on my table i load the first 10 row values when i add a row i want to get row value 11 but no matter what i do i cant get it i even get one of the first 10 row values or none at all i wanted to show you my whole script but this website wouldnt allow me so i just show you my refresh button since thats where i will add the method to add rows. and in my main sql method am loading the first 50 rows but only shows ten – Nick Demetraides Oct 14 '19 at 06:38
  • _i wanted to show you my whole script but this website wouldnt allow me_ Upload your code to another Web site - that allows you to post all your code - and then [edit] your question and add a link to your uploaded code. – Abra Oct 14 '19 at 07:21
  • Didnt think of adding a link i feel dumb sorry https://serverfault.com/questions/987870/trying-to-get-the-next-values-of-my-sql-data-to-jtable I also changed the code a bit since i last posted – Nick Demetraides Oct 14 '19 at 08:26
  • The code from that link contains **_LOTS_** of compiler errors. Please post code that compiles. – Abra Oct 14 '19 at 15:15

0 Answers0