java - Updating a JTable from query -
Currently I have derbydb and a UI on which jettbell is. Now I also have a bunch of classes, but people with whom I need help are from my So what I am doing now is checking my data, and then trying to push it to my geelabal in my second category, and I do not know how to create a link Start separating your UI from data management. Instead of returning a For example ... Then, in Then call the For example ... SensorDBConnection and
myUI
myUI where my JTable is, And what I want to do is update my JTable with my query which is located on my
SensorDBConnection
SensorDBConnection A snippet that works because this system. Is happening
DefaultTableModel model; // Confused model = new DefaultTableModel (); // Confused jTable1 = new JTable (model); // Confused Model AddColumn ("TIME"); model.addColumn ("SENSORID"); Model.addColumn ("floating"); Model.addColumn ("we"); Model.addColumn ("light"); Model.addColumn ("voltage"); While (results.next ()) {time = results.getInt (1); Id = results.getInt (2); Temp = results.getInt (3); We = results. GetInt (4); Light = results.getInt (5); Voltage = results.getInt (6); model.addRow (new object [] {time, id, floating, we, light, voltage}); Sensor senses = new sensors (id, floating, we, light, voltage); sensors.add (Sens); //System.out.println(sens); } Results.close (); Stmt.close ();
TableModel to
sensor DBC connection , can it return data that will need to create a data model ...
Public category sensor expands DBiNation ... {public list & lt; Sensor & gt; LoadData () {List & lt; Sensor & gt; Sensor = new arrelisted & lt; & Gt; (25); try {// ... while (results.next ()) {time = results.getInt (1); Id = results.getInt (2); Temp = results.getInt (3); We = results. GetInt (4); Light = results.getInt (5); Voltage = results.getInt (6); model.addRow (new object [] {time, id, floating, we, light, voltage}); Sensor senses = new sensors (id, floating, we, light, voltage); sensors.add (Sens); }} Finally {try {results.close (); } Hold (Exception Exp) {try} {stmt.close (); } Catch (exception XP) {}} return sensor; }}
MyUI , you will simply request sensor data and create your
TableModel . To simplify your life, make a custom
TableModel , which is how to deal with
sensor ...
Public category sensor tab model extends AbstractTableModel so far {protected constant last string [COLUMN_NAMES = {"TIME", "SENSORID", "TEMP", "HUM", "LIGHT", "VOLTAGE"}; Private listing & lt; Sensor & gt; Sensor; Public sensorable model (list & lt; sensor & gt; sensor) {this.sensors = sensors; } @ Override public string returned getColumnName (integer column) {COLUMN_NAMES [column] returned; } @ Override Public Intravert () {Return Sensor. (); } @ Override Public Ent column columns () {Return COLUMN_NAMES; } @ Override public object getValueAt (int rowIndex, int columnIndex) {sensor sensor = sensIndex;); Object value = null; Switch (column index) {case 0: value = sensor.getTime (); break; Case 1: value = sensor.getID (); break; Case 2: Value = sensor .getTemp (); break; Case 3: value = censor.gethum (); break; Case 4: Value = Sensor; Gatelight (); break; Case 5: value = sensor; gate voltage (); break; } return value; }}
loadData method in your
MyUI class by
SensorDBConnection and simply Create an
example of TableModel and apply it to the JTable example that you already have ...
public class MyUI extension ... {Private JTable Table; Private sensorBC connection sensor; // ... protected zero loadtable content () {table model model = zero; Try {model = new sensorable model (sensor. Load data)); } Grip (escloxation XP) {// handle exception} table.setmodel (model); }}
Comments
Post a Comment