| | |
general query procedure
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2007
Posts: 242
Reputation:
Solved Threads: 0
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?
(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?
Java Syntax (Toggle Plain Text)
mysql> SELECT artist,song,book_title,page_num FROM content WHERE artist LIKE "%b lue oyster cult%"; +------------------+-----------------------+------------------------------------ +----------+ | artist | song | book_title | page_num | +------------------+-----------------------+------------------------------------ +----------+ | Blue Oyster Cult | Don t Fear the Reaper | Guitar Tab White Pages Vol 1 | 210 | | Blue Oyster Cult | Godzilla | Guitar Tab White Pages Vol 1 | 271 | | Blue Oyster cult | Burning for you | Guitar Tab White Pages Vol 3 | 193 | | Blue Oyster Cult | Burning for You | The Greatest Rock Guitar Fake Book | 48 | | Blue Oyster Cult | Dont Fear the Reaper | The Greatest Rock Guitar Fake Book | 97 | +------------------+-----------------------+------------------------------------ +----------+ 5 rows in set (0.02 sec) mysql>
Java Syntax (Toggle Plain Text)
@Action public Task search() { return new SearchTask(getApplication()); } private class SearchTask extends Task { private String searchQuery; private List searchList; SearchTask(org.jdesktop.application.Application app) { super(app); searchList = org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList()); } //public <PropertyType> get<PropertyName>(); @Override protected Void doInBackground() { try { setProgress(0, 0, 4); setMessage("Rolling back the current changes..."); setProgress(1, 0, 4); entityManager.getTransaction().rollback(); Thread.sleep(1000L); // remove for real app setProgress(2, 0, 4); setMessage("Starting a new transaction..."); entityManager.getTransaction().begin(); Thread.sleep(500L); // remove for real app setProgress(3, 0, 4); setMessage("Fetching new data..."); java.util.Collection data = query.getResultList(); Thread.sleep(1300L); // remove for real app setProgress(4, 0, 4); Thread.sleep(150L); // remove for real app searchList.clear(); searchList.addAll(data); } catch(InterruptedException ignore) { } return null; }
Last edited by ceyesuma; Jan 26th, 2008 at 8:24 am. Reason: format
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
----------------------------------------------
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
•
•
Join Date: Aug 2007
Posts: 242
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
Connection con = DriverManager.getConnection(url, "Fernanda", "J8"); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet srs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES"); WHILE(rst.next()) ResultSet srs = stmt.executeQuery("select COF_Name from COFFEES " + "where price = 7.99"); 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.
Java Syntax (Toggle Plain Text)
entityManager = javax.persistence.Persistence.createEntityManagerFactory("splashbookdbPU").createEntityManager(); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(splashapp.SplashApp.class).getContext().getResourceMap(SplashView.class); query = entityManager.createQuery(resourceMap.getString("query.query")); // NOI18N list = org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
Last edited by ceyesuma; Jan 26th, 2008 at 10:15 pm.
•
•
Join Date: Aug 2007
Posts: 242
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Next Thread: very basic
Views: 1482 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop machine map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test threads time transfer tree unlimited utility webservices windows






