general query procedure

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 242
Reputation: ceyesuma is an unknown quantity at this point 
Solved Threads: 0
ceyesuma ceyesuma is offline Offline
Posting Whiz in Training

general query procedure

 
0
  #1
Jan 26th, 2008
Please find attached Doc2.doc. It is a pic of my program.
(this program successfully outputs the entire database. Yet I would like to learn the general steps to click the search button and perform a query.
further please find the method I have for a search @Action.
I am not clear on the procedure.
I have to write the query (below) in the java format. I think I have to change the query so it will conform to libraries???
Any way I am not sure of the right way to
1. make the query.
2. create a list
3.add the result set to a list
4.display the list in the textarea.
Could someone describe the steps to begin this?

  1. mysql> SELECT artist,song,book_title,page_num FROM content WHERE artist LIKE "%b
  2. lue oyster cult%";
  3. +------------------+-----------------------+------------------------------------
  4. +----------+
  5. | artist | song | book_title
  6. | page_num |
  7. +------------------+-----------------------+------------------------------------
  8. +----------+
  9. | Blue Oyster Cult | Don t Fear the Reaper | Guitar Tab White Pages Vol 1
  10. | 210 |
  11. | Blue Oyster Cult | Godzilla | Guitar Tab White Pages Vol 1
  12. | 271 |
  13. | Blue Oyster cult | Burning for you | Guitar Tab White Pages Vol 3
  14. | 193 |
  15. | Blue Oyster Cult | Burning for You | The Greatest Rock Guitar Fake Book
  16. | 48 |
  17. | Blue Oyster Cult | Dont Fear the Reaper | The Greatest Rock Guitar Fake Book
  18. | 97 |
  19. +------------------+-----------------------+------------------------------------
  20. +----------+
  21. 5 rows in set (0.02 sec)
  22.  
  23. mysql>

  1. @Action
  2. public Task search() {
  3. return new SearchTask(getApplication());
  4. }
  5.  
  6. private class SearchTask extends Task {
  7. private String searchQuery;
  8. private List searchList;
  9.  
  10.  
  11. SearchTask(org.jdesktop.application.Application app) {
  12. super(app);
  13.  
  14. searchList = org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
  15.  
  16. }
  17. //public <PropertyType> get<PropertyName>();
  18.  
  19.  
  20. @Override protected Void doInBackground() {
  21. try {
  22. setProgress(0, 0, 4);
  23. setMessage("Rolling back the current changes...");
  24. setProgress(1, 0, 4);
  25. entityManager.getTransaction().rollback();
  26. Thread.sleep(1000L); // remove for real app
  27. setProgress(2, 0, 4);
  28.  
  29. setMessage("Starting a new transaction...");
  30. entityManager.getTransaction().begin();
  31. Thread.sleep(500L); // remove for real app
  32. setProgress(3, 0, 4);
  33.  
  34. setMessage("Fetching new data...");
  35. java.util.Collection data = query.getResultList();
  36. Thread.sleep(1300L); // remove for real app
  37. setProgress(4, 0, 4);
  38.  
  39. Thread.sleep(150L); // remove for real app
  40. searchList.clear();
  41. searchList.addAll(data);
  42. } catch(InterruptedException ignore) { }
  43. return null;
  44. }
Last edited by ceyesuma; Jan 26th, 2008 at 8:24 am. Reason: format
Attached Files
File Type: doc Doc2.doc (538.0 KB, 9 views)
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: general query procedure

 
0
  #2
Jan 26th, 2008
Go through the JDBC tutorials, then go through the Swing tutorials, then, make sure you don't mix the two into the same class.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 242
Reputation: ceyesuma is an unknown quantity at this point 
Solved Threads: 0
ceyesuma ceyesuma is offline Offline
Posting Whiz in Training

Re: general query procedure

 
0
  #3
Jan 26th, 2008
  1. Connection con = DriverManager.getConnection(url, "Fernanda", "J8");
  2.  
  3. Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
  4. ResultSet.CONCUR_READ_ONLY);
  5. ResultSet srs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");
  6.  
  7. WHILE(rst.next())
  8.  
  9. ResultSet srs = stmt.executeQuery("select COF_Name from COFFEES " +
  10. "where price = 7.99");
  11. srs.next();

I went thru that material and it all look farmiliar.
The program I am trying to understand and work with uses this kind of code.
I am not sure where to begin maybe I "binding" or persistance.
If I could find a good example to see what is going on with this code.

  1. entityManager = javax.persistence.Persistence.createEntityManagerFactory("splashbookdbPU").createEntityManager();
  2. org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(splashapp.SplashApp.class).getContext().getResourceMap(SplashView.class);
  3. query = entityManager.createQuery(resourceMap.getString("query.query")); // NOI18N
  4. list = org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
Last edited by ceyesuma; Jan 26th, 2008 at 10:15 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 242
Reputation: ceyesuma is an unknown quantity at this point 
Solved Threads: 0
ceyesuma ceyesuma is offline Offline
Posting Whiz in Training

Re: general query procedure

 
0
  #4
Jan 28th, 2008
public interface EntityManager

Interface used to interact with the persistence context.

An EntityManager instance is associated with a persistence context. A persistence context is a set of entity instances in which for any persistent entity identity there is a unique entity instance. Within the persistence context, the entity instances and their lifecycle are managed. This interface defines the methods that are used to interact with the persistence context. The EntityManager API is used to create and remove persistent entity instances, to find entities by their primary key, and to query over entities.

The set of entities that can be managed by a given EntityManager instance is defined by a persistence unit. A persistence unit defines the set of all classes that are related or grouped by the application, and which must be colocated in their mapping to a single database.
Last edited by ceyesuma; Jan 28th, 2008 at 1:24 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1482 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC