Matriculating this year, we used Ready to Program from Gr 8 - Gr 10, then switched to jGrasp and have been using that ever since.
How do you connect to a DB from outside the IDE?
Here's the code that we were taught to connect - NOTE: doesn't work with 2007
import java.sql.*;
private Connection conn = null;
public static void makeConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(
"jdbc

dbc

RIVER={Microsoft Access Driver (*.mdb)};DBQ=DBNAME.mdb ");
//file's name is "DBNAME.mdb" and is in the same directory as the
//.java & .class file -- this will change to point to the right file
//an absolute or relative path is possible, but the method shown is
//probably best for exam conditions where files 'move'
System.out.println("Connection successful");
}
catch(Exception e)
{
System.out.println("Failed to get connection");
e.printStackTrace();
}
}
Then to do stuff we used SQL like the following:
try
{
Statement stmt = conn.createStatement();
//SQL to query the database
ResultSet rs = stmt.executeQuery("SELECT * FROM tblCD");
while(rs.next())
{
String Artist = rs.getString("Artist");
String Title = rs.getString("Title");
//etc. etc. etc. for the remaining fields
//print to screen -->> not very pretty, we just want to see it work!
System.out.println("Artist: " + Artist + "\nTitle: "+Title);
}
rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
Probably not nicely spaced on the forum, but there it is.