Creating a Simple Web Application Using an SQLite Database


Prerequisites

NetBeans Web Plugins HOWTO
HOWTO configure NetBeans for SQLite

Directions

Login to Fedora in the CSc labs.

Download the database creation script.  (http://users.csc.calpoly.edu/~jdalbey/308/Resources/wrestlerDB.sql)

Create the sample database.  Open a terminal window and navigate to the folder
that contains the database creation script (wrestlerDB.sql), enter the boldface commands:

% sqlite3 /tmp/wrestlerDB
SQLite version 3.5.6
Enter ".help" for instructions
sqlite> .read wrestlerDB.sql
sqlite> .tables
Counselor  Subject  
sqlite> .quit
%


Download the sample application. (http://www.netbeans.org/files/documents/4/1851/IFPWAFCAD.zip)

Unzip it into your NetBeansProjects folder.

Start NetBeans. 
Select File -> Open
in the Open Project dialog, navigate to the IFPWAFCAD project,
click "Open Project".

An error message will appear "One or more projects use database
connections that have not been registered."  Click Close.

This message occurs because the project uses MySQL and
we haven't configured NetBeans to work with MySQL.
In fact, we are going to use SQLite instead.

In the Project tab, expand IFPWAFCAD, expand WebPages,
expand META-INF.  Double-click "context.xml".

In the edit window the database connection info appears:

<Context path="/IFPWAFCAD">
    <Resource name="jdbc/IFPWAFCAD" auth="Container" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000"
        username="root" password="nbuser" driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/MyNewDatabase"/>
</Context>


Replace the above with:

<Context path="/IFPWAFCAD">
    <Resource name="jdbc/IFPWAFCAD" auth="Container" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000"
        username="root" password="nbuser" driverClassName="org.sqlite.JDBC"
        url="jdbc:sqlite://tmp/wrestlerDB"/>
</Context>

Ctrl-S to save.

Now the project is prepared.
Select "Run Project" from the Run menu.
NetBeans should build your project and start Tomcat.
A web browser window should appear with the application start page:

index.jsp displayed in a browser

Select a subject from the drop-down menu, click Submit.
observe the course and counselor info that appears.



Troubleshooting
Q: On my personal computer, when I run the project, I get this error message from Tomcat: "Cannot load JDBC driver class 'org.sqlite.JDBC'"
A: Try copying the sqlite jar file to the tomcat lib folder.