Could you do a tutorial on best practices on calling model/db on a background thread via Javafx Task and ExecutorService? That would be valuable for a beginner like me.
Hi, JavaFX was designed with MVC in mind, hence the binding between view and the model. Decoupling them completely, as MVP typically requires, is likely to result in writing more boilerplate code. So I'm not sure if there's any value in implementing MVP over MVC, unless you're just curious what it's like, in which case I'd suggest googling it as there are existing examples. As for the graph demo, this can easily be done with MVC. The Model is the entire graph. We can expose two bindings: nodes and edges. Whenever either of them change, your View can listen for the events and redraw itself. Of course, a more interesting challenge is how to lay out the graph. There are numerous techniques for graph drawing. You can use Gephi - github.com/gephi/gephi to help you lay out the graph, which you can then visualize in JavaFX.
Hi Almas, What if we have 3 tables, Books, Authors & Copyrights and Books-Authors are in m-n relationship? I mean a book can have several authors and an author's name can be related to several books, too. Could you please give some tips how we can change the ListView to TableView in GUI part? Thanks a lot!
+Zhengyu Wang Hi, yes you are right. This is one of the reasons why I noted in the video description that this data organization isn't efficient. In RDB (relational databases) you would typically have AUTHORS table with unique author ID and their info such as first/last names, number of books published, country of origin, etc. BOOKS table with unique book ID and some info unique to books, like title, number of pages, original published year/language, etc. Then you could have a table that links unique book id to a unique author id. Please refer to the following links for more information: stackoverflow.com/questions/19170855/relational-database-for-multiple-authors-multiple-books stackoverflow.com/questions/13353231/how-write-down-to-database-multiple-authors-in-simple-books-table en.wikipedia.org/wiki/Unique_key As for TableView you can have a look at: github.com/AlmasB/FXCatalog/tree/master/src/main/java/com/almasb/fxcatalog It was never meant to be a tutorial, so code may be dodgy at times but should give you a basic idea on how to proceed with TableView
+Almas Baimagambetov (AlmasB) Many thanks, Almas! I am going to read the links! I did learn a lot from this video but did not anticipate that you could answer me today. Happy new year!
+Almas Baimagambetov (AlmasB) Hello again, Could you please offer some information about how to fix a pop-up window with input functions by clicking a button like "Add"? Using JavaFX FXML of course. Thanks!!
+Almas Baimagambetov (AlmasB) I am working on java desktop application (javafx) which needs to be install/run in three different computers on same Local Network ( LAN ). But this application need to share one database and each application should be able to insert, update, delete records in the same database. How do i achieved that in java, any suggestion/help would be appreciated ? And you mentioned that "this way of organizing data is very inefficient in RDB and shouldn't be used in production".. what is the best way to deal with database.?
You can either run a database on one of the three machines, which essentially becomes the server, or use the 4th machine to just run the database. Next step is to identify the internal IP address of that machine and use it when connecting from your client (the other 3) machines. In the video I stored a lot of redundant information, like name/author/date multiple times. I used the RDB like a Java List pretty much to try and simplify the tutorial. Ideally you will need to have a table which maps unique IDs with data IDs and then another table which maps data IDs with data (name/author/date). It is commonly known as data normalization. Luckily there is a lot of info about that on the Internet.
Hi, I am trying to develop a console project using your technique. I am trying to return a list of products from the database but it is running empty list. Can you plz help me with this code. In DerbyProductDAO.java public List findAllProducts() { try { return dbAccess.query(connection, "SELECT * FROM Products", new BeanListHandler(Product.class)); //returns an empty list from this block only } catch (Exception e) { e.printStackTrace(); } return EMPTY; //does not return this empty } In ProductOperation.java public void getallProduct() { List products = productDAO.findAllProducts(); if(products.size() > 0) { System.out.println(" Size of products is "+products.size()+" "); //this returns the size correctly, which is 24 System.out.println("Showing you products which are in the database"); for(int i = 0; i< products.size(); i++) { System.out.println("Id: "+products.get(i).getProductId()+"\t" //returns 0 +" Name: "+products.get(i).getProductName()+"\t" //returns null +" Price: "+products.get(i).getProductPrice()+"\t" //returns 0 +" Company: "+products.get(i).getProductCompany()+"\t" //returns null +" ExpiryDate: "+products.get(i).getExpiryDate()); //returns 0 } } }
+Zomes Rand Hi, the code looks OK. It seems that the database is storing those objects but with their default fields, e.g. 0, null. First thing to check would be your code that sets up/writes to the database. Unfortunately at the moment I don't have any spare time to continue the tutorials or help debugging code. So my recommendation would be to copy all the tutorial code - github.com/AlmasB/LibraryLoan and then adapt/replace parts that you need. Sorry for not being of more help. Kind regards
Could you do a tutorial on best practices on calling model/db on a background thread via Javafx Task and ExecutorService? That would be valuable for a beginner like me.
can you help me sir , how to upload image and retrieve from mysql database using mvc thanks in advance
In findBook method you could return - Collections.emptyList();
Yes, thanks for that. That's a much better alternative, I must've missed it.
Hi
How i can open it in NetBean software ? how i can contact you for more details ?
Thanks, man, useful
Excellent
That was amazing! Thanks.
Could you do a video on the MVP pattern in JavaFX? Maybe demonstrating a Graph structure? Like Adding/removing nodes/edges and so on?
Hi, JavaFX was designed with MVC in mind, hence the binding between view and the model. Decoupling them completely, as MVP typically requires, is likely to result in writing more boilerplate code. So I'm not sure if there's any value in implementing MVP over MVC, unless you're just curious what it's like, in which case I'd suggest googling it as there are existing examples. As for the graph demo, this can easily be done with MVC. The Model is the entire graph. We can expose two bindings: nodes and edges. Whenever either of them change, your View can listen for the events and redraw itself. Of course, a more interesting challenge is how to lay out the graph. There are numerous techniques for graph drawing. You can use Gephi - github.com/gephi/gephi to help you lay out the graph, which you can then visualize in JavaFX.
you scared me about beginner but i have little knowledge about java, javafx and jdbc will i full understanding?
you are the best
Hi Almas,
What if we have 3 tables, Books, Authors & Copyrights and Books-Authors are in m-n relationship? I mean a book can have several authors and an author's name can be related to several books, too.
Could you please give some tips how we can change the ListView to TableView in GUI part?
Thanks a lot!
+Zhengyu Wang Hi, yes you are right. This is one of the reasons why I noted in the video description that this data organization isn't efficient. In RDB (relational databases) you would typically have AUTHORS table with unique author ID and their info such as first/last names, number of books published, country of origin, etc. BOOKS table with unique book ID and some info unique to books, like title, number of pages, original published year/language, etc. Then you could have a table that links unique book id to a unique author id. Please refer to the following links for more information:
stackoverflow.com/questions/19170855/relational-database-for-multiple-authors-multiple-books
stackoverflow.com/questions/13353231/how-write-down-to-database-multiple-authors-in-simple-books-table
en.wikipedia.org/wiki/Unique_key
As for TableView you can have a look at: github.com/AlmasB/FXCatalog/tree/master/src/main/java/com/almasb/fxcatalog
It was never meant to be a tutorial, so code may be dodgy at times but should give you a basic idea on how to proceed with TableView
+Almas Baimagambetov (AlmasB) Many thanks, Almas! I am going to read the links! I did learn a lot from this video but did not anticipate that you could answer me today. Happy new year!
+Almas Baimagambetov (AlmasB)
Hello again,
Could you please offer some information about how to fix a pop-up window with input functions by clicking a button like "Add"? Using JavaFX FXML of course. Thanks!!
Hi, what do you mean by "fix a pop-up window"? Can you also provide the use case, as I don't quite understand what you are trying to do.
Thanks for this video. I'm new to Java and JavaFX but with this video, I know my bearings. Thanks a million.
Hi.. can you make tutorial about how to handle database access( one database ) for distributed application in LAN
+Lalmuanawma khiangte Hi, do you mean DBMS --- Server --- Client?
+Almas Baimagambetov (AlmasB)
I am working on java desktop application (javafx) which needs to be install/run in three different computers on same Local Network ( LAN ). But this application need to share one database and each application should be able to insert, update, delete records in the same database.
How do i achieved that in java, any suggestion/help would be appreciated ?
And you mentioned that "this way of organizing data is very inefficient in RDB and shouldn't be used in production".. what is the best way to deal with database.?
You can either run a database on one of the three machines, which essentially becomes the server, or use the 4th machine to just run the database. Next step is to identify the internal IP address of that machine and use it when connecting from your client (the other 3) machines.
In the video I stored a lot of redundant information, like name/author/date multiple times. I used the RDB like a Java List pretty much to try and simplify the tutorial. Ideally you will need to have a table which maps unique IDs with data IDs and then another table which maps data IDs with data (name/author/date). It is commonly known as data normalization. Luckily there is a lot of info about that on the Internet.
+Almas Baimagambetov (AlmasB) Thanks !! I'm hoping to see more great JavaFX tutorial.. cheers :D
Thanks, very usefull.
Hi, I am trying to develop a console project using your technique.
I am trying to return a list of products from the database but it is running empty list. Can you plz help me with this code.
In DerbyProductDAO.java
public List findAllProducts() {
try {
return dbAccess.query(connection, "SELECT * FROM Products", new BeanListHandler(Product.class));
//returns an empty list from this block only
} catch (Exception e) {
e.printStackTrace();
}
return EMPTY; //does not return this empty
}
In ProductOperation.java
public void getallProduct() {
List products = productDAO.findAllProducts();
if(products.size() > 0) {
System.out.println("
Size of products is "+products.size()+"
");
//this returns the size correctly, which is 24
System.out.println("Showing you products which are in the database");
for(int i = 0; i< products.size(); i++) {
System.out.println("Id: "+products.get(i).getProductId()+"\t" //returns 0
+" Name: "+products.get(i).getProductName()+"\t" //returns null
+" Price: "+products.get(i).getProductPrice()+"\t" //returns 0
+" Company: "+products.get(i).getProductCompany()+"\t" //returns null
+" ExpiryDate: "+products.get(i).getExpiryDate()); //returns 0
}
}
}
+Zomes Rand Hi, the code looks OK. It seems that the database is storing those objects but with their default fields, e.g. 0, null. First thing to check would be your code that sets up/writes to the database. Unfortunately at the moment I don't have any spare time to continue the tutorials or help debugging code. So my recommendation would be to copy all the tutorial code - github.com/AlmasB/LibraryLoan and then adapt/replace parts that you need. Sorry for not being of more help. Kind regards
very usefull
just what was that? and i thought that i was a advanced java programmer.I have to accept that i barely get lost in the code.