JavaFX - Database + Table


JavaFX + Apache Derby Database + JDBC - I have seen several queries related to this, hence thought of providing a sample application. In order to avoid any back-end database setup, I'm using Embedded Derby which will create database in <UserHome>/JavaFXDatabase/. The Derby jars are hosted as separate JNLP extension - ApacheDerby.jnlp - which is referenced in application jnlp files.

Click "Populate" button to add some dummy data to the Table.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/JavaFXDatabase/JavaFXDatabase.js"></script>


To launch click on above image or

Note: Application may take a little longer to download due to large size of Derby jar files. Application will show two certificate dialogs - One for application and another for Derby Extension. These permissions are required so as to create database in user's home directory.

Database access code is same as any other java application - DBUtils.java. The table is implemented using Rectangle, Label and Panel Layout. Its not really scalable as its not using any virtual concepts, all nodes are real. The approach can be used for simple applications. Please refer to CustomerTable.fx for more information.

Try it out and let me know feedback..

..and that brings the end of this year's blogs. It was nice sharing all the information with you.. "See" you next year!

Merry Christmas and Happy New Year to All.. Have Fun!


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/JavaFXDatabase/zoneit.js"></script>

Comments:

Hello Sir Menon!

I always read your blog! I liked this application.

In Brazil, people always ask for applications that use database. Can I post this in portuguese, explaining some parts of the code???

Thanks for this!

Merry Christmas and Happy New Year

Posted by William Antônio on December 23, 2009 at 08:48 PM IST #

@William Antônio Sure! Please feel free to enhance/translate/share.. If possible provide a link here..

Posted by Rakesh Menon on December 23, 2009 at 10:10 PM IST #

Ah .. most awaiting post :). thanks !

Posted by Vaibhav Choudhary on December 30, 2009 at 02:45 AM IST #

Hi Rakesh,

Is it possible to place the controls (like checkbox, textbox,etc) in the custom table cells?. Such that when the user clicks on checkbox(for ex.) that row need to be saved in some other object.If possible can we access those controls state for further processing?

Posted by Siva on January 20, 2010 at 09:05 AM IST #

Wow Like to Java SE but maybe differnt code but same program I Like it

Posted by Miyugi on February 17, 2010 at 01:34 PM IST #

@Miyugi Thanks! Yes! :)

Posted by Rakesh Menon on February 17, 2010 at 01:42 PM IST #

Dear Rakesh Menon ,
thank you for your code, i'am a new user to Javafx, i would like to connect not to derby database but to mysql database how can i do, using you code , i have database mysql.
tank for your reply

Posted by Maxit on February 24, 2010 at 02:17 PM IST #

@Maxit the approach used for connecting to MySQL will be same as any other java application, change will be in connection driver and url

URL: "jdbc:mysql://<db-host>:<db-port>/<db-name>"
Driver: "com.mysql.jdbc.Driver"

db-port will be 3306 by default.

Reference:
http://dev.mysql.com/usingmysql/java/

Posted by Rakesh Menon on February 25, 2010 at 07:51 AM IST #

Dear Rakesh,

Thank you for your answer, but i have error when i run the code could you hepl me please? this is the error that i have:
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.runtime.provider.GUIRuntimeProvider$1.run(GUIRuntimeProvider.java:65)
at com.sun.javafx.tk.swing.SwingToolkit$StartupRoutine.run(SwingToolkit.fx:582)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.UnsupportedOperationException: Not implemented yet

Posted by maxit on February 27, 2010 at 04:49 AM IST #

Dear Rakesh,

Thank you for your answer, but i have error when i run the code could you hepl me please? this is the error that i have:
ERROR: Could not load driver!
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javafxdatabase.DBUtils.<init>(DBUtils.java:61)
at javafxdatabase.Main.<clinit>(Main.fx:40)
at javafxdatabase.Main.<clinit>(Main.fx:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.runtime.provider.GUIRuntimeProvider$1.run(GUIRuntimeProvider.java:65)
at com.sun.javafx.tk.swing.SwingToolkit$StartupRoutine.run(SwingToolkit.fx:582)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.runtime.provider.GUIRuntimeProvider$1.run(GUIRuntimeProvider.java:65)
at com.sun.javafx.tk.swing.SwingToolkit$StartupRoutine.run(SwingToolkit.fx:582)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:derby:C:\\Users\\Eric/JavaFXDatabase/sample;create=true
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at javafxdatabase.DBUtils.<init>(DBUtils.java:68)
at javafxdatabase.Main.<clinit>(Main.fx:40)
at javafxdatabase.Main.<clinit>(Main.fx:40)
... 14 more
browser-run:
jws-run:
midp-run:
run:
BUILD SUCCESSFUL (total time: 10 seconds)

Posted by maxit on February 27, 2010 at 07:55 AM IST #

@maxit I'm not able to find the exact issue, from stack trace, looks like Derby driver is not in classpath
>
> ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
>
>

You need to have following jars in classpath - derby.jar, derbyclient.jar, derbynet.jar

Also test the connection and entire DB setup using pure java command line application. This will ensure that the setup is proper. Then you can integrate it to JavaFX.

Posted by Rakesh Menon on March 01, 2010 at 02:53 AM IST #

Dear Rakesh,

how can i diplay the popup windows to ask me to confirm delete customer select when i want to delete the customer. thank you

Posted by Maxit on March 05, 2010 at 03:20 AM IST #

@Maxit Yes, you can use Alert.question and based on return type, decide whether to delete or not.

http://java.sun.com/javafx/1.2/docs/api/javafx.stage/javafx.stage.Alert.html

Posted by Rakesh Menon on March 05, 2010 at 05:54 AM IST #

Thank You very much Mr Rakesh for your help

Posted by Maxit on March 05, 2010 at 07:01 AM IST #

have you use databinding ? if no it is possible to use databinding with this exemple and how?
thank you?

Posted by bruno on March 05, 2010 at 03:27 PM IST #

@bruno I haven't tried, I think it will be feasible to write a layer on top of swing-binding implementation to support this. I haven't investigated this yet.

Posted by Rakesh Menon on March 09, 2010 at 06:12 AM IST #

Hi Rakesh,
This not work in my PC.

ERROR: Could not load driver!
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)

and more...
thank you?

Posted by guest on March 10, 2010 at 02:10 PM IST #

@77.163.152.219 Can you provide some more information about OS, JRE-Version, Browser etc.

Also can you directly visit below URL to see if its able to download the jars and cache it. It will take a while, so may be due to some network issue its not able to download these jars.

http://mediacast.sun.com/users/rakeshmenonp/media/ApacheDerby.jnlp

Posted by Rakesh Menon on March 11, 2010 at 01:10 AM IST #

Dear Rakesh , can you refer me where can i find to write a layer on top of swing-binding implementation to support this?

Posted by Bruno on March 11, 2010 at 07:11 AM IST #

If a ask you it is because i want to make the same thing using silverlight and compare , it is because i ask it is possible to use databinding with javafx , i want to use for my thesis, the title of my thesis is Javafx and Silverlight exemple of databinding.if it not possible to use databinding with javafx for this kind of exemple tell me also
thank you for your answer and help

Posted by bruno on March 11, 2010 at 07:17 AM IST #

@bruno JavaFX as such does not support this. But it must be feasible to modify the swing binding and remove swing dependency (expose functionality via listener interface). As of now the generated code is tightly coupled with swing, we must work backwards so as to remove this dependency.

https://beansbinding.dev.java.net/
http://www.netbeans.com/kb/docs/java/gui-binding.html

Posted by Rakesh Menon on March 11, 2010 at 12:00 PM IST #

thank then it is not possible actually make databinding using Javafx?
thank You for your answer

Posted by Bruno on March 15, 2010 at 11:41 AM IST #

@Bruno If you are looking for out-of-box solution (using just APIs in JavaFX), its not supported.

Posted by Rakesh Menon on March 17, 2010 at 06:52 AM IST #

Post a Comment:
Comments are closed for this entry.
About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« August 2015
SunMonTueWedThuFriSat
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
     
Today