This TOTD (Tip Of The Day) shows how to create a Persistence Unit (PU) for a MySQL database usingNetBeans IDE. This PU can then be used in any of Java EE artifacts (JSP, Servlet, EJB, ...) for database interaction.
  1. In NetBeans IDE, create a new project
  2. Set up the database
  3. Create and configure the persistence unit
  4. Create a Servlet to perform the database operations
Now let's try it!

Invoking "curl http://localhost:8080/Autocomplete/StatesServlet?abbrev=CA" shows the following output on command prompt:

Found California with abbrev "CA"

Alternatively, you can enter this URL in browser as well to see the output as:

Invoking "http://localhost:8080/Autocomplete/StatesServlet?abbrev=CB" shows the output:

Even though MySQL is used as the database in this case, any other database can be easily used for creating this portable PU.

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive of all tips is available here.

Technorati: totd mysql jpa persistenceunit netbeans glassfish
Technorati: totd mysql jpa persistenceunit netbeans glassfish jquery autocomplete