-2

I try to load database value into textfield. this code is not showing any error. But it also not giving result. It showing blank textfield.

      try
         {
           connection = database_controller.dbconnect();

          String query = "Select * from newlead2 where SERIAL_NO ='lead_id'";
           resultset = database_controller.dbExecuteQuery(query);



                    /*preparedstatement =connection.prepareStatement(query);
                    resultset =preparedstatement.executeQuery();*/
                    while(resultset.next())
                    {
                            String FN = resultset.getString("CUSTOMER_NAME");
                            Customer_Name.setText(FN);
                    }  
                }
        catch(SQLException ex)
        {
        System.err.println("Error:" + ex);
        }
  • 1
    How are you setting up your UI? Without seeing that, there is no way to give suggestions. textField.setText("value"); should work just fine. More than likely Customer_Name isn't on the scene. – purring pigeon Mar 08 '18 at 16:22
  • @FXML private static TextField Customer_Name; – CodeQ Technology Mar 08 '18 at 16:28
  • 2
    Of course the `ResultSet` could also be empty... Furthermore it's suspicious that the `SERIAL_NO` coulumn is compared to a string that does not look much like a serial number. – fabian Mar 08 '18 at 16:28
  • `@FXML private static TextField Customer_Name;` [will not inject anything](https://stackoverflow.com/questions/23105433/javafx-8-compatibility-issues-fxml-static-fields) into the `Customer_Name` field. But, generally, this question is unanswerable without a [MCVE]. – James_D Mar 08 '18 at 16:32
  • i have accessed "lead_id" from tableview – CodeQ Technology Mar 08 '18 at 16:33
  • when i remove static then it showing error "Non-static variable name cannot referenced from a static context " – CodeQ Technology Mar 08 '18 at 16:37
  • Then, obviously, don't reference it from a static context. It makes just as little sense to do that as it does to make it static in the first place. You still haven't explained why you are passing a literal string as the value to which you're comparing the id, and you still haven't posted an example which demonstrates the problem. – James_D Mar 08 '18 at 16:40
  • @James_D I have upload complete code at https://codeqtechnology.blogspot.in/2018/03/how-to-load-database-value-into.html you may go through – CodeQ Technology Mar 08 '18 at 16:57
  • No; I'm not going to go through your entire project (and neither is anyone else on this site). Doing so would be no help at all to any other user. Create (from scratch) a [MCVE] that demonstrates the problem, and post it in the question. – James_D Mar 08 '18 at 16:59

1 Answers1

0

I’m going off what you posted in the comments. You aren’t connected to the database, so your resultset is empty. Put in some code to test if these variables are empty. But like others have said it is too hard to answer this question without a more concise example.

user2213630
  • 3
  • 1
  • 2
  • 4
  • If there were no connection to the database, the code would throw an exception. – James_D Mar 08 '18 at 18:46
  • You are right James. It would throw an Exception. Even going to his code on the site he provided in the comments, their is not enough information to determine the answer. – user2213630 Mar 08 '18 at 20:04