Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. JSpinner Value into Database?

JSpinner Value into Database?

Scheduled Pinned Locked Moved Java
databasequestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chdboy
    wrote on last edited by
    #1

    How would I get the JSpinner value into database?, the value is in alphanumeric Like 1month 2month

    String[] monthStrings = {"1Month","3Month","6Month","1Year"};
    SpinnerListModel monthModel = new SpinnerListModel(monthStrings);
    JSpinner spinner = new JSpinner(monthModel);

    L 1 Reply Last reply
    0
    • C chdboy

      How would I get the JSpinner value into database?, the value is in alphanumeric Like 1month 2month

      String[] monthStrings = {"1Month","3Month","6Month","1Year"};
      SpinnerListModel monthModel = new SpinnerListModel(monthStrings);
      JSpinner spinner = new JSpinner(monthModel);

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      chdboy wrote:

      How would I get the JSpinner value into database?

      The same way you would put any value into the database; what exactly is the difficulty? Given also that it is just a short list, maybe storing the index value rather than the string would be the best idea.

      Veni, vidi, abiit domum

      C 1 Reply Last reply
      0
      • L Lost User

        chdboy wrote:

        How would I get the JSpinner value into database?

        The same way you would put any value into the database; what exactly is the difficulty? Given also that it is just a short list, maybe storing the index value rather than the string would be the best idea.

        Veni, vidi, abiit domum

        C Offline
        C Offline
        chdboy
        wrote on last edited by
        #3

        Here is the code ,how I'm saving the JSpinner value

        statement.setString(27,JSpinner.getValue());

        Under setString red line and the error is

        The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, Object)

        and Under

        JSpinner.getValue()

        red line and error says

        Cannot make a static reference to the non-static method getValue() from the type JSpinner

        L 1 Reply Last reply
        0
        • C chdboy

          Here is the code ,how I'm saving the JSpinner value

          statement.setString(27,JSpinner.getValue());

          Under setString red line and the error is

          The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, Object)

          and Under

          JSpinner.getValue()

          red line and error says

          Cannot make a static reference to the non-static method getValue() from the type JSpinner

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You cannot use JSpinner.getValue(), you need to call getValue() on an instance of the JSpinner class.

          Veni, vidi, abiit domum

          C 1 Reply Last reply
          0
          • L Lost User

            You cannot use JSpinner.getValue(), you need to call getValue() on an instance of the JSpinner class.

            Veni, vidi, abiit domum

            C Offline
            C Offline
            chdboy
            wrote on last edited by
            #5

            I tried

            statement.setString(27,(String)spinner.getValue());

            and I get

            Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

            EDIT: It worked with

            statement.setString(27,(String)spinner.getValue().toString());

            L 1 Reply Last reply
            0
            • C chdboy

              I tried

              statement.setString(27,(String)spinner.getValue());

              and I get

              Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

              EDIT: It worked with

              statement.setString(27,(String)spinner.getValue().toString());

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You should go back to your Java documentation or tutorials and learn why and when it is possible to use casts. Simply stated, you cannot use a cast to convert one object type to another. You also need to decide in advance what object type you want to store in the database, and write the code to handle that specific situation.

              Veni, vidi, abiit domum

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups