Conversion failed when converting the “invalid” value 'Residential' to data type int










1














How do I convert data that is given from result set string.
I am trying to show the drop down box gui as a text but give it a value of 1 and 2



what I want it to show as for drop down choice is right:
https://i.imgur.com/gDKAkDX.png



but I need the actual values to be 1 and 2 correspondingly



Then I need to put those values back into a database f key that only allows int...



final ObservableList options = FXCollections.observableArrayList();


public void fillComboBox()
Connection c;


try
Connection conn = null;
Statement stmt = null;
String queryx = "Select CusType_ID, CusTypeName from CustomerType";

ResultSet jrs = c.createStatement().executeQuery(queryx);

while (jrs.next())

String custyID = jrs.getString("CusType_ID");
String custyN = jrs.getString("CusTypeName");


options.add(new MyObject(custyID,custyN));
typeBox.setItems(options);

catch (SQLException e)
e.printStackTrace();





String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getValue() +"')";









share|improve this question




























    1














    How do I convert data that is given from result set string.
    I am trying to show the drop down box gui as a text but give it a value of 1 and 2



    what I want it to show as for drop down choice is right:
    https://i.imgur.com/gDKAkDX.png



    but I need the actual values to be 1 and 2 correspondingly



    Then I need to put those values back into a database f key that only allows int...



    final ObservableList options = FXCollections.observableArrayList();


    public void fillComboBox()
    Connection c;


    try
    Connection conn = null;
    Statement stmt = null;
    String queryx = "Select CusType_ID, CusTypeName from CustomerType";

    ResultSet jrs = c.createStatement().executeQuery(queryx);

    while (jrs.next())

    String custyID = jrs.getString("CusType_ID");
    String custyN = jrs.getString("CusTypeName");


    options.add(new MyObject(custyID,custyN));
    typeBox.setItems(options);

    catch (SQLException e)
    e.printStackTrace();





    String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getValue() +"')";









    share|improve this question


























      1












      1








      1







      How do I convert data that is given from result set string.
      I am trying to show the drop down box gui as a text but give it a value of 1 and 2



      what I want it to show as for drop down choice is right:
      https://i.imgur.com/gDKAkDX.png



      but I need the actual values to be 1 and 2 correspondingly



      Then I need to put those values back into a database f key that only allows int...



      final ObservableList options = FXCollections.observableArrayList();


      public void fillComboBox()
      Connection c;


      try
      Connection conn = null;
      Statement stmt = null;
      String queryx = "Select CusType_ID, CusTypeName from CustomerType";

      ResultSet jrs = c.createStatement().executeQuery(queryx);

      while (jrs.next())

      String custyID = jrs.getString("CusType_ID");
      String custyN = jrs.getString("CusTypeName");


      options.add(new MyObject(custyID,custyN));
      typeBox.setItems(options);

      catch (SQLException e)
      e.printStackTrace();





      String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getValue() +"')";









      share|improve this question















      How do I convert data that is given from result set string.
      I am trying to show the drop down box gui as a text but give it a value of 1 and 2



      what I want it to show as for drop down choice is right:
      https://i.imgur.com/gDKAkDX.png



      but I need the actual values to be 1 and 2 correspondingly



      Then I need to put those values back into a database f key that only allows int...



      final ObservableList options = FXCollections.observableArrayList();


      public void fillComboBox()
      Connection c;


      try
      Connection conn = null;
      Statement stmt = null;
      String queryx = "Select CusType_ID, CusTypeName from CustomerType";

      ResultSet jrs = c.createStatement().executeQuery(queryx);

      while (jrs.next())

      String custyID = jrs.getString("CusType_ID");
      String custyN = jrs.getString("CusTypeName");


      options.add(new MyObject(custyID,custyN));
      typeBox.setItems(options);

      catch (SQLException e)
      e.printStackTrace();





      String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getValue() +"')";






      java sql scenebuilder






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 3:52

























      asked Nov 10 at 1:10









      a p

      83




      83






















          1 Answer
          1






          active

          oldest

          votes


















          0














          First create a class for storing the CusType_ID and CusTypeName in dropdown(combobox)



          public class MyObject 

          private String key;
          private String value;

          public MyObject(String key, String value)
          this.key = key;
          this.text = value;


          public String getKey()
          return key ;


          @Override
          public String toString()
          return value;




          then store the value from your request



           String queryx = "Select CusType_ID, CusTypeName from CustomerType";

          ResultSet rs = c.createStatement().executeQuery(queryx);

          while (rs.next())
          int recordNumber = 1;
          int recNumber =2;

          String sx = rs.getString("CusTypeName");
          String customerID = rs.getString("CusType_ID");


          typeBox.addItem(new MyObject(customerID, sx));





          Finally, get your value back from selected item and store it in your new sql



          Object item = comboBox.getSelectedItem();
          String value = ((MyObject)item).getKey();
          String sql = "INSERT INTO Customer (CustomerType_ID) VALUES ("+
          value +");" ;





          share|improve this answer




















          • I don't know why I am getting this error. ChoiceBox$ChoiceBoxSelectionModel cannot be cast to sample.MyObject, my comboBox is named typeBox
            – a p
            Nov 10 at 3:49











          • i Updated my code so you could better understand it, I also made that separate class like you made.
            – a p
            Nov 10 at 3:53






          • 1




            nvm I GOT IT. thank you so much. for some reason my call is different for the selection. It had to be Object item = typeBox.getSelectionModel().getSelectedItem();
            – a p
            Nov 10 at 4:00











          • I'm sorry for the late reply, did it worked? , if not it might you didn't choose the selected item --> String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getSelectedItem().getValue() +"')"; , please let me know if you want any think else
            – Sari Masri
            Nov 10 at 13:29











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235174%2fconversion-failed-when-converting-the-invalid-value-residential-to-data-type%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          First create a class for storing the CusType_ID and CusTypeName in dropdown(combobox)



          public class MyObject 

          private String key;
          private String value;

          public MyObject(String key, String value)
          this.key = key;
          this.text = value;


          public String getKey()
          return key ;


          @Override
          public String toString()
          return value;




          then store the value from your request



           String queryx = "Select CusType_ID, CusTypeName from CustomerType";

          ResultSet rs = c.createStatement().executeQuery(queryx);

          while (rs.next())
          int recordNumber = 1;
          int recNumber =2;

          String sx = rs.getString("CusTypeName");
          String customerID = rs.getString("CusType_ID");


          typeBox.addItem(new MyObject(customerID, sx));





          Finally, get your value back from selected item and store it in your new sql



          Object item = comboBox.getSelectedItem();
          String value = ((MyObject)item).getKey();
          String sql = "INSERT INTO Customer (CustomerType_ID) VALUES ("+
          value +");" ;





          share|improve this answer




















          • I don't know why I am getting this error. ChoiceBox$ChoiceBoxSelectionModel cannot be cast to sample.MyObject, my comboBox is named typeBox
            – a p
            Nov 10 at 3:49











          • i Updated my code so you could better understand it, I also made that separate class like you made.
            – a p
            Nov 10 at 3:53






          • 1




            nvm I GOT IT. thank you so much. for some reason my call is different for the selection. It had to be Object item = typeBox.getSelectionModel().getSelectedItem();
            – a p
            Nov 10 at 4:00











          • I'm sorry for the late reply, did it worked? , if not it might you didn't choose the selected item --> String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getSelectedItem().getValue() +"')"; , please let me know if you want any think else
            – Sari Masri
            Nov 10 at 13:29
















          0














          First create a class for storing the CusType_ID and CusTypeName in dropdown(combobox)



          public class MyObject 

          private String key;
          private String value;

          public MyObject(String key, String value)
          this.key = key;
          this.text = value;


          public String getKey()
          return key ;


          @Override
          public String toString()
          return value;




          then store the value from your request



           String queryx = "Select CusType_ID, CusTypeName from CustomerType";

          ResultSet rs = c.createStatement().executeQuery(queryx);

          while (rs.next())
          int recordNumber = 1;
          int recNumber =2;

          String sx = rs.getString("CusTypeName");
          String customerID = rs.getString("CusType_ID");


          typeBox.addItem(new MyObject(customerID, sx));





          Finally, get your value back from selected item and store it in your new sql



          Object item = comboBox.getSelectedItem();
          String value = ((MyObject)item).getKey();
          String sql = "INSERT INTO Customer (CustomerType_ID) VALUES ("+
          value +");" ;





          share|improve this answer




















          • I don't know why I am getting this error. ChoiceBox$ChoiceBoxSelectionModel cannot be cast to sample.MyObject, my comboBox is named typeBox
            – a p
            Nov 10 at 3:49











          • i Updated my code so you could better understand it, I also made that separate class like you made.
            – a p
            Nov 10 at 3:53






          • 1




            nvm I GOT IT. thank you so much. for some reason my call is different for the selection. It had to be Object item = typeBox.getSelectionModel().getSelectedItem();
            – a p
            Nov 10 at 4:00











          • I'm sorry for the late reply, did it worked? , if not it might you didn't choose the selected item --> String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getSelectedItem().getValue() +"')"; , please let me know if you want any think else
            – Sari Masri
            Nov 10 at 13:29














          0












          0








          0






          First create a class for storing the CusType_ID and CusTypeName in dropdown(combobox)



          public class MyObject 

          private String key;
          private String value;

          public MyObject(String key, String value)
          this.key = key;
          this.text = value;


          public String getKey()
          return key ;


          @Override
          public String toString()
          return value;




          then store the value from your request



           String queryx = "Select CusType_ID, CusTypeName from CustomerType";

          ResultSet rs = c.createStatement().executeQuery(queryx);

          while (rs.next())
          int recordNumber = 1;
          int recNumber =2;

          String sx = rs.getString("CusTypeName");
          String customerID = rs.getString("CusType_ID");


          typeBox.addItem(new MyObject(customerID, sx));





          Finally, get your value back from selected item and store it in your new sql



          Object item = comboBox.getSelectedItem();
          String value = ((MyObject)item).getKey();
          String sql = "INSERT INTO Customer (CustomerType_ID) VALUES ("+
          value +");" ;





          share|improve this answer












          First create a class for storing the CusType_ID and CusTypeName in dropdown(combobox)



          public class MyObject 

          private String key;
          private String value;

          public MyObject(String key, String value)
          this.key = key;
          this.text = value;


          public String getKey()
          return key ;


          @Override
          public String toString()
          return value;




          then store the value from your request



           String queryx = "Select CusType_ID, CusTypeName from CustomerType";

          ResultSet rs = c.createStatement().executeQuery(queryx);

          while (rs.next())
          int recordNumber = 1;
          int recNumber =2;

          String sx = rs.getString("CusTypeName");
          String customerID = rs.getString("CusType_ID");


          typeBox.addItem(new MyObject(customerID, sx));





          Finally, get your value back from selected item and store it in your new sql



          Object item = comboBox.getSelectedItem();
          String value = ((MyObject)item).getKey();
          String sql = "INSERT INTO Customer (CustomerType_ID) VALUES ("+
          value +");" ;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 1:53









          Sari Masri

          1297




          1297











          • I don't know why I am getting this error. ChoiceBox$ChoiceBoxSelectionModel cannot be cast to sample.MyObject, my comboBox is named typeBox
            – a p
            Nov 10 at 3:49











          • i Updated my code so you could better understand it, I also made that separate class like you made.
            – a p
            Nov 10 at 3:53






          • 1




            nvm I GOT IT. thank you so much. for some reason my call is different for the selection. It had to be Object item = typeBox.getSelectionModel().getSelectedItem();
            – a p
            Nov 10 at 4:00











          • I'm sorry for the late reply, did it worked? , if not it might you didn't choose the selected item --> String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getSelectedItem().getValue() +"')"; , please let me know if you want any think else
            – Sari Masri
            Nov 10 at 13:29

















          • I don't know why I am getting this error. ChoiceBox$ChoiceBoxSelectionModel cannot be cast to sample.MyObject, my comboBox is named typeBox
            – a p
            Nov 10 at 3:49











          • i Updated my code so you could better understand it, I also made that separate class like you made.
            – a p
            Nov 10 at 3:53






          • 1




            nvm I GOT IT. thank you so much. for some reason my call is different for the selection. It had to be Object item = typeBox.getSelectionModel().getSelectedItem();
            – a p
            Nov 10 at 4:00











          • I'm sorry for the late reply, did it worked? , if not it might you didn't choose the selected item --> String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getSelectedItem().getValue() +"')"; , please let me know if you want any think else
            – Sari Masri
            Nov 10 at 13:29
















          I don't know why I am getting this error. ChoiceBox$ChoiceBoxSelectionModel cannot be cast to sample.MyObject, my comboBox is named typeBox
          – a p
          Nov 10 at 3:49





          I don't know why I am getting this error. ChoiceBox$ChoiceBoxSelectionModel cannot be cast to sample.MyObject, my comboBox is named typeBox
          – a p
          Nov 10 at 3:49













          i Updated my code so you could better understand it, I also made that separate class like you made.
          – a p
          Nov 10 at 3:53




          i Updated my code so you could better understand it, I also made that separate class like you made.
          – a p
          Nov 10 at 3:53




          1




          1




          nvm I GOT IT. thank you so much. for some reason my call is different for the selection. It had to be Object item = typeBox.getSelectionModel().getSelectedItem();
          – a p
          Nov 10 at 4:00





          nvm I GOT IT. thank you so much. for some reason my call is different for the selection. It had to be Object item = typeBox.getSelectionModel().getSelectedItem();
          – a p
          Nov 10 at 4:00













          I'm sorry for the late reply, did it worked? , if not it might you didn't choose the selected item --> String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getSelectedItem().getValue() +"')"; , please let me know if you want any think else
          – Sari Masri
          Nov 10 at 13:29





          I'm sorry for the late reply, did it worked? , if not it might you didn't choose the selected item --> String sql = "INSERT INTO Customer [CustomerType_ID]) VALUES" typeBox.getSelectedItem().getValue() +"')"; , please let me know if you want any think else
          – Sari Masri
          Nov 10 at 13:29


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235174%2fconversion-failed-when-converting-the-invalid-value-residential-to-data-type%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Edmonton

          Crossroads (UK TV series)