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 from Database.

JSpinner value from Database.

Scheduled Pinned Locked Moved Java
questiondatabasetutorial
2 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

    I have this code which saves the value into database from JSpinner

    SpinnerListModel monthModel = new SpinnerListModel();
    String[] monthStrings = {"1Month","3Month","6Month","1Year"}; //get month names
    monthModel = new SpinnerListModel(monthStrings);
    JSpinner spinner = new JSpinner(monthModel);
    statement.setString(28,(String)monthModel.getValue().toString().toUpperCase());

    But how to get that value back for Editing? I tried

    spinner.setText((String)monthModel.getValue(),29);

    But it says

    The method setText(String, int) is undefined for the type JSpinner

    How do I get the values from Database?again to JSpinner.

    J 1 Reply Last reply
    0
    • C chdboy

      I have this code which saves the value into database from JSpinner

      SpinnerListModel monthModel = new SpinnerListModel();
      String[] monthStrings = {"1Month","3Month","6Month","1Year"}; //get month names
      monthModel = new SpinnerListModel(monthStrings);
      JSpinner spinner = new JSpinner(monthModel);
      statement.setString(28,(String)monthModel.getValue().toString().toUpperCase());

      But how to get that value back for Editing? I tried

      spinner.setText((String)monthModel.getValue(),29);

      But it says

      The method setText(String, int) is undefined for the type JSpinner

      How do I get the values from Database?again to JSpinner.

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      You should have a database layer. It should NOT have any gui code in it. It provides a public API that allows an external caller to interact with the layer. The layer interacts with the database. That public API would have a method/class that would represent "save interval" and "get interval" where the 'interval' values represent '1 month', '3 Months', '6 months' (and note that I am NOT saying to store "1 month" as a value.) The 'save' method uses a database insert or perhaps update statement. And the 'get' uses a database query statement. You code that and test it. After you do that THEN your gui code, specifically the JSpinner uses the two methods.

      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