i am currently qorkin on a term project where i am basically creating a registration system for students enrolled in some college and i have predefined classes that I have to fill in methods...the only problem is I can't seem to find any information on how to define a vector to get all the prerequisite info from a prereq table based on the course ID...I tried writing a parameterized sql statement but kep getting a count error which i have researched...and gotten nowhere...i'm lost and need help hahahaha....here is my code for the Data Adapter class
I have many more DA classes to fill in so if i can get help on this one I know i can figure out the rest on my own. Thnak you ahead of time for any help thrown out there...
Quick edit: the Access database table contains three columns:
1)prerequisiteentryID (autonumber)
2)courseID (long integer)
3)prerequisiteID (long integer)
import java.sql.*;
import java.util.*;
import javax.swing.*;
public class PrerequisitesDA
{
//we will store a connection reference in the data item 'conn' That will be passed in
//as a constructor argument
private Connection conn;
private Vector v;
private boolean noRecs;
PrerequisitesDA(Connection c)
{
conn = c;
v=null;
noRecs = false;
}
//=========================================================================================
// methods that we need here:
// 1. getAllForCourse(int courseID) will get all database prerequisite records for this course
// 2. noPrerequisites() returns true if no recs were returned;
//===========================================================================================
public Vector getAllForCourse(int courseID)
{
String sql=null;
ResultSet rs=null;
boolean moreRecords=false;
Prerequisite p=null;
int cid, pcid;
int i;
v = new Vector();
sql = "SELECT courseID, prerequisiteID FROM prerequisites WHERE courseID = ?;";
try
{
Statement st = conn.createStatement();
rs = st.executeQuery(sql);
moreRecords = rs.next();
noRecs = false;
if(!moreRecords)
{
noRecs = true;
return null;
}
while(moreRecords)
{
cid = rs.getInt(1);
pcid = rs.getInt(2);
p = new Prerequisite();
p.setCourseID(cid);
p.setPrerequisiteCourseID(pcid);
v.addElement(p);
moreRecords = rs.next();
}
}// end of try
catch(Exception e)
{
System.out.println(e.toString());
System.exit(0); // for testing, this is ok
}
return v;
}
public boolean noPrerequisites()
{
return noRecs;
}
}
Message was edited by:
djmd02