JXTable Databinding JDBC

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

HI,

I had come across what looked like a goood simple example of JXTable with JDBC
The example is below.

However i can not find the databinding.jar anywhere because it says it is not being used any more.  What will be replacing it?  Is there an example like this one using the replacement jar or is there another place i can download the databinding.jar

import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
 
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
 
import org.jdesktop.binding.swingx.adapter.DataModelToTableModelAdapter;
import org.jdesktop.dataset.DataSet;
import org.jdesktop.dataset.adapter.TabularDataModelAdapter;
import org.jdesktop.dataset.provider.sql.JDBCDataConnection;
import org.jdesktop.dataset.provider.sql.SQLCommand;
import org.jdesktop.dataset.provider.sql.SQLDataProvider;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.AlternateRowHighlighter;
import org.jdesktop.swingx.decorator.Highlighter;
import org.jdesktop.swingx.decorator.HighlighterPipeline;
import org.jdesktop.swingx.table.TableColumnExt;

public class MyTable{
 
        private JXTable jxTable;
 
        private DataTable dataTable;
 
        private TabularDataModelAdapter tabAdapter;
 
        private SQLDataProvider provider;
 
        private DataModelToTableModelAdapter tableModelAdapter;
 
        private SQLCommand sqlCommand;
 
        public MyTable () {
 
        }
 
        public JComponent init() {
                // TODO code application logic here
                DataSet ds = new DataSet();
                dataTable = new DataTable(ds);
                dataTable.createColumns();
 
                // JDBC:
                provider = new SQLDataProvider();
 
                JDBCDataConnection dataConnection = MyConnection.getInstance()
                                .getDataConnection();
 
                dataConnection.setConnected(true);
                provider.setConnection(dataConnection);
 
                sqlCommand = new SQLCommand();
                String strSql = "SELECT * FROM table_name";
                sqlCommand.setSelectSQL(strSql);
                provider.setCommand(sqlCommand);
 
                tabAdapter = new TabularDataModelAdapter(dataTable);
 
                tableModelAdapter = new DataModelToTableModelAdapter(tabAdapter);
 
                jxTable.setModel(tableModelAdapter);
                jxTable.setAutoCreateColumnsFromModel(false);
 
               
               
                provider.load(dataTable);
                dataTable.clear();
                dataTable.load();
 
                jxTable.setColumnControlVisible(true);
                return new JScrollPane(jxTable);
        }
                }
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=285411

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The DataBinding part is mostly available in the DataBinding subproject at
https://databinding.dev.java.net/ but I'm not sure what condition it's in.
The project is no longer active, supposedly replaced by BeansBinding JSR295.
The source is in the CVS but a lot of it is under different branches than main

All of the DataSet/DataTable/SQLDataProvider stuff is now in the DataBuffer subproject.
https://databuffer.dev.java.net/  It was split out from DataBInding and is in fairly good
condition.
This is now a defunct project unfortunately. It seems to have petered out.

I have developed my own models to bind to a JXTable using DataBuffer - it is very easy.
If you are interested I will post an example to the incubator.
[Message sent by forum member 'rturnbull' (rturnbull)]

http://forums.java.net/jive/thread.jspa?messageID=285529

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes that would be great.  I am new here where is the incubator?
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=285546

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Yes that would be great.  I am new here where is the
> incubator?

I'll post a link when I've done it. It will be a couple of days before I get time.

The incubator is here: https://jdnc-incubator.dev.java.net/
[Message sent by forum member 'rturnbull' (rturnbull)]

http://forums.java.net/jive/thread.jspa?messageID=285560

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Great.  Thanks again
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=285877

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have posted to the incubator a very simple TableModel and a demo program
linking a DataTable to a JXTable. Can be found at
https://jdnc-incubator.dev.java.net/source/browse/jdnc-incubator/src/rturnbull/java/datatablemodel/

You will need Swingx and DataBuffer jars

This is a very simple readonly table.
Note that everything is controlled by the array of DataColumn names passed to
the DataModel.

In my application I have modded the DataColumn to add additional metadata.
I add a Label, which I use for the TableHeader names, so in the DataModel,
getColumnNames() becomes
[code]
        public String getColumnName(int column) {
                return dTable.getColumn(colNames[column]).getLabel();
        }
[/code]
I also added an integer scale, which for String fields defines the maximum allowable
length, and for numeric (BigDecimal) fields, I use in my ColumnFactory to display
the correct number of decimal places


There should also be something listening to the DataTable for any changes,
e.g a DataTableEventAdapter, to fire changes on the model if the DataTable changes.

Hope this helps.
[Message sent by forum member 'rturnbull' (rturnbull)]

http://forums.java.net/jive/thread.jspa?messageID=285879

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

looks pretty straight froward.

So with the addition of some loops , a DB connection and a Database result set i should be able to use this to get that data into this model?

Thanks again
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=286035

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> So with the addition of some loops , a DB connection
> and a Database result set i should be able to use
> this to get that data into this model?

I don't fully understand this.
If you are looking to use DataBuffer, you don't need a result set. DataBuffer includes the
API to easily load an SQL database directly into a DataTable, which replaces the
ResultSet.
If you are looking to copy the data from a ResultSet to a DataTable, I don't think that is
the way to go.
The only reason I would use a ResultSet rather than DataBuffer is if I was accessing
a large database, and/or required a scrollable cursor.
I don't think DataBuffer has been used with large databases. (And how large is large is
undefined. All data is in memory - I don't know if that is how ResultSet works).
[Message sent by forum member 'rturnbull' (rturnbull)]

http://forums.java.net/jive/thread.jspa?messageID=286118

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Im kinda new to the whole jtable thing.  My company uses borland dataset and sets it to the jtable which is all taken care of in the higher level classes.  so i really dont have to mess with it. I am basically teaching myself about jtables just because i would like to know how they work.  i have worked with them before with ressult sets.  I really like to functionalit of the JXTable.  can you point me in the right direction as to loading SQL database directly into a DataTable.

Thank again for being patient
John
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=286119

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think your initial query about databinding sent me down the wrong path.

If you can bind your dataset to a JTable, then you should be able to replace your
JTable with a JXTable without any changes.
That's if its a swing JTable. A Borland jtable may be different. In which case I would
suggest the Sun java tutorial on JTables, specifically the section on creating a table model.
Anywhere you can use a swing JTable, you can replace it with a JXTable.

If you wish to persist with DataBuffer/DataTable, there is very little (read 'no')
 documentation. You would have to pull the source from CVS and generate the JavaDoc
yourself.
I could write a small pseudo code program to outline the steps required if you still want
to proceed
[Message sent by forum member 'rturnbull' (rturnbull)]

http://forums.java.net/jive/thread.jspa?messageID=286124

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

well we use xml files to store the table information.  then we have our own jtable class.  and we use the dataset along with it. eg.

DataSet ds = parentScreen.getDS("TABLE_NAME")

JTable jt = parentScreen.getJTable();

jt.setDataSet(ds);

Thats it.  We use other methods to fill the DS from the DB but they were written long ago.  Then all we do is manipulate the DS and it reflects on the JTable.

What i am doing here is for my own use.  I dont want to do something as large scale as what i do at work.  

All I want to do is query ad DB put the data in the table, and manipulate the data when needed.  I didnt think you needed to create a table model when filling it from the DB.

I have filled table like this: (not full source code) eg.

ResultSetMetaData md = rs.getMetaData();
            int columns = md.getColumnCount();
 
            //  Get column names
 
            for (int i = 1; i <= columns; i++)
            {
                columnNames.addElement( md.getColumnName(i) );
            }
 
            //  Get row data
 
            while (rs.next())
            {
                Vector row = new Vector(columns);
 
                for (int i = 1; i <= columns; i++)
                {
                    row.addElement( rs.getObject(i) );
                }
 
                data.addElement( row );
            }
 
            rs.close();
            ps.close();

new JTable(data, columnNames);


But i would like to use DataBuffer/DataTable going forward.

Thanks again
John
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=286127

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry I took so long to get back to you - got distracted by other things. (It's school
holidays here)

To use DataBuffer you need to perform the following steps:
a) Define a JDBCDataConnection for your database and setConnected(true). You use
this for all tables.
b) Define a DataSet.
c) Define DataTable and add DataColumns. If you wish the system to generate SQL
commands and you are updating, you must specify the key columns with
DataColumn#setKeyColumn(true)
d) Define an SQLDataProvider specifying the database table name. This will automatically
generate basic SQL statements for you. You can also specify your own SQL statements.
See DataBuffer javadoc for DataProvider and SQLCommand.
e) Set the connection from a) in your SQLDataProvider, with SQLDataProvider#setConnection().
f) Set the DataProvider in the DataTable with DataTable#setProvider().
g) Read your table with DataTable#loadAndWait(). You can also use DataTable#load() to
load table asynchronously. This is intended, I think, for large tables or slow connections.
However I feel there is a bug with large tables (> 50 records) in that event notifying load
complete can be sent before the load has completed. (It also happens with
loadAndWait, but its not such a problem.)
h) If required do a DataTable#saveAndWait() to write any changes back to the database.
Note that after the load, there is no data connection with the database. Any changes
made to the DataTable are not reflected in the database unless a save is performed.

I hope I've covered everything. Any questions don't hesitate to ask.
If we can get more people using this we may get it resurrected. (With you I think it makes 3 ;) )
[Message sent by forum member 'rturnbull' (rturnbull)]

http://forums.java.net/jive/thread.jspa?messageID=287788

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok 2 things

Do i need to do [code]dTable.createColumn(Long.class, "taxas_year"); [/code]
for all the columns or just the key col?

I also keep getting this error:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"tax_assm"' at line 1"

[code]
dTable = new DataTable(new DataSet("ds"), "datatable");

                        DataColumn col = dTable.createColumn(String.class, "pty_code");
                        col.setKeyColumn(true);

                        dTable.createColumn(Long.class, "taxas_year");
                        dTable.createColumn(Long.class, "taxas_value");
                        dTable.createColumn(Long.class, "taxas_impvalue");
                        dTable.createColumn(Long.class, "taxas_tvalue");
                        dTable.createColumn(Long.class, "taxas_mvyear");
                        dTable.createColumn(Long.class, "taxas_mlvalue");
                        dTable.createColumn(Long.class, "taxas_mivalue");
                        dTable.createColumn(Long.class, "taxas_tmvalue");
                        dTable.createColumn(String.class, "tax_assr");

                       

                        JDBCDataConnection dataConnection =
                                new JDBCDataConnection("com.mysql.jdbc.Driver", "jdbc:mysql://192.168.1.4:8500/afdb", "xxxx", "xxxxxxxx");

                        dataConnection.setConnected(true);
                       
                        provider = new SQLDataProvider("tax_assm");
                        provider.setConnection(dataConnection);
                        dTable.setDataProvider(provider);
                        dTable.load();
[/code]

I feel like im on th eright track but what am i missing?

Thanks again
John
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=287805

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Actually it is creating the statement like this
select * from "tax_assm"

is this a bug that it puts quotes around the table name?
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=287862

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You need to create columns for all table columns you wish to access.

You still need a table model to connect to a JXTable. The DataTable is a stand-alone
entity.


> Actually it is creating the statement like this
> select * from "tax_assm"
>
> is this a bug that it puts quotes around the table
> name?

This is an old recognized problem - see thread
http://forums.java.net/jive/thread.jspa?messageID=141405𢡝
As development was stopped, nothing was done.
It also puts quotes around column names on update statements

As I see it, you have a number of options.
You can provide your own select statement to SQLCommand.
You can modify TableCommand#getSelectStatement() to not include the
quotes (assuming you are only using mySQL.)
The problem with these is you would also have to adjust all the other statements -
update, insert etc.
I understand, with mySQL, you can set the mode to ANSI_QUOTES which could
overcome the problem  

(I currently use an MS Access database with JDBC:ODBC and it doesn't seem to
mind the quotes)
[Message sent by forum member 'rturnbull' (rturnbull)]

http://forums.java.net/jive/thread.jspa?messageID=287876

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok,  I got things working.  However is there ways to format the data.  the columns i have that return years are being returned as 2,007.  What is the best way to format the data types?  all the efields in the DB are integer fields.
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=287879

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Ok,  I got things working.  However is there ways to
> format the data.  the columns i have that return
> years are being returned as 2,007.  What is the best
> way to format the data types?  all the efields in the
> DB are integer fields.

I assume you are talking about how it displays in the JXTable.

By default JXTable creates DefaultTableRenderers for the common classes, including
Number which uses the default NumberFormat for your locale.
To override this, you can set a new class wide default renderer,
e.g myTable.setDefaultRenderer(Number.class, new DefaultTableRenderer(StringValue.TO_STRING)
or any other formatting StringValue.
Alternatively, you can override for individual columns by extending ColumnFactory and
overriding ColumnFactory#configureTableColumn() and set a CellRenderer for
the column.
[Message sent by forum member 'rturnbull' (rturnbull)]

http://forums.java.net/jive/thread.jspa?messageID=287883

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Awsome.  This is going to be a great addition to this data entry program I have written.

Now on saving the table i am getting the following:

20 Jul 2008 02:40:43,609 - Jul 20, 2008 2:40:43 AM org.jdesktop.databuffer.provider.SaveTask run
WARNING: SQLCommand not configured with an update sql statement
java.lang.Exception: SQLCommand not configured with an update sql statement
        at org.jdesktop.databuffer.provider.sql.SQLCommand.getUpdateStatement(SQLCommand.java:181)
        at org.jdesktop.databuffer.provider.sql.SQLDataProvider$2.saveData(SQLDataProvider.java:214)
        at org.jdesktop.databuffer.provider.SaveTask.run(SaveTask.java:48)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)


Is this part of that other problem?

I hope the start developing this again.  This is a great and easy way to work with jtables.

Thanks again for all your help
john
[Message sent by forum member 'jonnyd91' (jonnyd91)]

http://forums.java.net/jive/thread.jspa?messageID=287887

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: JXTable Databinding JDBC

by jdnc-interest