Created by: gwideman, Jun 6, 2012 4:26 pm
Revised by: gwideman, Oct 1, 2012 2:04 pm (16 revisions)

Overview

Notes on exploring some aspects of NetBeans (7.2 Development version)
  • Project structure and file layout
    • Correspondence between NB Projects vs executables and libraries (seems different than IntelliJ)
  • A basic GUI app
    • How to make the look-and-feel look native on Windows
  • Components
    • Text control to which lines of text can be added incrementally (ie: like TMemo).
    • Tree
    • Table
  • Connecting to a database
    • Connecting to MS Access
    • Defining the DSN (ie: mdb file) in code, (without needed Data Sources control panel)

General NetBeans notes

  • IDE supports multiple floating windows (ie: viewing more than one file at a time in source or design view) Hallelujah!
  • Can copy and paste controls from one design view to another, and this evidently copies related event code.
  • Changing names of controls seems to change corresponding references to these controls in the source (ie: not just declarations and event-handler names).

Project structure and file layout

  • Project window
    • This lists all projects that are "open".
      • There is no particular relationship between open projects?
    • A project contains a directory structure:
      • build
      • nbproject
      • src
        • source files, or
        • package directories containing
          • source files
        • Can include source for multiple executables (ie: multiple classes with a main()).
      • test?
      • build.xml
      • manifest.mf

A basic GUI app

Detour to get MySQL ODBC driver set up

I want to use an already-installed MySQL database to test NetBeans data connectivity, but in order to independently test connections to MySQL I want to use Access to talk to MySQL first. OK, so I need a MySQL ODBC driver to work first.
  • This used to be easy on WinXP, now trying in Win 7 64.
  • Downloaded driver from here: http://dev.mysql.com/downloads/connector/odbc/
    • I chose x86 32-bit, on the basis that Access 2010 is 32-bit (I think), and so is the JVM (I think).
  • Installed OK, but
    • In Access, I tried to set up a link to an ODBC table, which takes you through the process of:
      • Machine Data Source > New > "You are logged in with non-Admin privileges. System DSNs could not be created or modified" (and doesn't allow providing Admin credentials. Then proceeds to "Create New Data Source".
        • User Data Source
        • MySQL ODBC 5.1 Driver... Finish
        • MySQL Connector/ODBC Data Source Configuration dialog
          • MySQLTestConn2 127.0.0.1 33066 admin2/admin2pwd Database: nbtest01
          • Test button succeeds
        • Link Tables: select testtable
          • Access adds testtable link to the list of Tables
          • Opening the table shows the data
        • HOWEVER: If you need to change the data in the User DSN, the Data Source Configuration dialog doesn't save the data properly, and you have to edit the data in the registry
    • On attempting to use Windows Programs > Administative Tools > "Data Sources (ODBC)":
      • If I try to set up a new System DSN for MySQL, no MySQL driver appears to be installed.
      • If I try to edit the DSNs set up by Access, I get message "The setup routines for the MySQL ODBC 5.1 Driver ODBC driver could not be found. Please reinstall the driver." Errors found: The specified DSN contains and architecture mismatch between the Driver and Application"
      • SOLUTION: The default Data Sources (ODBC) is the 64 bit version. To manage 32-bit ODBC drivers, we need the 32 bit version, at:
        • C:\WINDOWS\SysWOW64\odbcad32.exe I made a shortcut to that, and it seems to work fine for editing the MySQL DSNs.

Connecting NetBeans to a database

Connecting NetBeans to an Access database

  • The connection parameters needed for NetBeans New Connection wizard:
    • References
    • Driver name: JDBC-ODBC Bridge
    • Username: [none]
    • Password [none]
    • JDBC URL:
      • jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=F:/Proj_Test/JavaNetBeans/DBApp01/testdata/TestData.mdb
      • Test Connection button succeeded
      • Note use of forward slashes. Neither backslashes or double backslashes worked.
      • I have not tried a path with spaces in it.
      • Username and password being blank was OK
    • This created a new node in the Services tab > Databases tree, labeled jdbc:odbc:Driver={... etc etc
      • Under which opens a list of Tables, Views, Procedures
      • Under TestTable2 appear its fields, indexes and foreign keys
  • Creating a form for the Access DB's table. Again following: Binding Beans and Data in a Java Application, section Binding Data to Components.
    • Creating Entity Classes
    • New > Other > Persistence > Entity class from database >
    • New Entity Classes from Database dialog
Stuck. Looks like we need a detour to investigate the alternatives for a database that a desktop Java app can treat as "embedded" (not requiring separate install of a server), yet can be accessed ad hoc via the usual Windows database tools, such as Access and Excel, probably via ODBC.
Detour to explore alternative desktop-ish databases that can be accessed with NetBeans (or Java apps in general) and also via MS Access (using ODBC or other driver). Desktop databases with JDBC and ODBC

Connecting to SQLite database

  • Download SQLite JDBC driver from Xerial project.
  • Locate jar at: C:\usr\local\lib\sqlite-jdbc-3.7.2.jar
    • Add C:\usr\local\lib\ to CLASSPATH?
  • In NetBeans Databases > Drivers, add an item for SQLite and point it to this jar file
  • In NetBeans Databases > add new connection > New Connection Wizard
    • Choose SQLite driver
    • JDBC URL: jdbc:sqlite:F:/Proj_Test/JavaNetBeans/DBApp02/data/places.db3 (Test file from firefox.)
      • Test Connection works OK
      • Connection item appears under Databases, and shows tables. Opening the tables shows PK fields and Indexes.
  • Following the GUI Binding tutorial again: http://netbeans.org/kb/docs/java/gui-binding.html
  • Creating Entity Classes
    • Shows all available tables, but several, including moz_places, are marked not available due to lacking a primary key (when they actually have one). This may be due to the bug(s) discussed here: https://www.netbeans.org/bugzilla/show_bug.cgi?id=167389
      • So, I should try the 201206070001 build.
  • OK, new build fixes the primary key problem
  • Rest of tutorial proceeds smoothly. Data from SQLite can be displayed fine in JTable.

More advanced database-related issues

  • Display and sync of Master-detail tables in separate grids.
    • Sync of multiple views on same records in general