Help me in java!!

Discussion in 'Web Design & Coding' started by Bretenn, Oct 28, 2002.

  1. Bretenn

    Bretenn Guest

    i'm running a java prog in realj which resulting ....

    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2494)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:334)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:249)
    at form.LoginDialog.actionPerformed(LoginDialog.java:81)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
    at java.awt.Component.processMouseEvent(Component.java:3715)
    at java.awt.Component.processEvent(Component.java:3544)
    at java.awt.Container.processEvent(Container.java:1164)
    at java.awt.Component.dispatchEventImpl(Component.java:2593)
    at java.awt.Container.dispatchEventImpl(Container.java:1213)
    at java.awt.Component.dispatchEvent(Component.java:2497)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
    at java.awt.Container.dispatchEventImpl(Container.java:1200)
    at java.awt.Window.dispatchEventImpl(Window.java:914)
    at java.awt.Component.dispatchEvent(Component.java:2497)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)

    what do these things mean (in plain english is prefer 10q)
     
  2. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    You tried to run an SQL query of some sort. The call, however had too few arguments. It wants two and you only supplied one or none.
     
  3. Bretenn

    Bretenn Guest

    this is some of the coding...
    private University(){
    name = "World Virtual University";
    studentList = new ArrayList();
    employeeList = new ArrayList();
    classroomList = new ArrayList();
    startConnection();
    }

    public String getUniversityName(){
    return name;
    }

    public Student getStudent(int value){
    return (Student)studentList.get(value);
    }

    public Iterator getAllStudent(){
    return studentList.iterator();
    }

    public Classroom getClassroom(int value){
    return (Classroom)classroomList.get(value);
    }

    public Iterator getAllClassroom(){
    return classroomList.iterator();
    }

    public Staff getStaff(int value){
    Object e = employeeList.get(value);
    if (e instanceof Administrator)
    return (Administrator)e;
    else if (e instanceof Lecturer)
    return (Lecturer)e;
    else if (e instanceof Manager)
    return (Manager)e;
    else return (Staff)e;
    }

    public int getStaffNumber(){
    return employeeList.size();
    }

    public Iterator getAllStaff(){
    return employeeList.iterator();
    }

    public void addStaff(String staffID,String name,String boGender,
    String ic,String address,String telhome,
    String telhp,String fax,String email,
    String password,String remark,
    String boGroupType,String position,String salary,
    String department){
    try{
    Statement statement1 = connection.createStatement();
    String valid = "SELECT * FROM Student WHERE staffid ='" +
    staffID + "'";
    ResultSet rs = statement1.executeQuery(valid);
    if ( rs.next()){
    JOptionPane.showMessageDialog(null,"Duplicate Staff ID Found!",
    "Error", JOptionPane.ERROR_MESSAGE);
    return;
    }
    }catch(SQLException sqlex){}
    try{
    if (validateStaffAction(staffID,name,boGender,ic,address,telhome,telhp,fax,email,
    password,remark,boGroupType,position,salary,department)){
    Statement statement = connection.createStatement();
    String query = "INSERT INTO Staff(staffid,name,gender,ic,address,telhome,telhp,fax,email,password,remark,grouptype,employedas,salary,department) "+
    "VALUES ('" + staffID + "', '" + name + "', '" + boGender +
    "', '" + ic + "', '" + address + "', '" + telhome + "', '" +
    telhp + "', '" + fax + "', '" + email + "', '" + password + "', '" +
    remark + "', '" + boGroupType + "', '" + position + "', '" +
    salary + "', '" + department + "')";
    int result = statement.executeUpdate(query);
    if ( result == 1 ){
    double sa = Double.parseDouble(salary);
    if( boGender.equalsIgnoreCase("1") ){
    employeeList.add(new Staff(staffID,name,boGender,ic,address,
    telhome,telhp,fax,email,password,remark,position,sa,department));
    }else if ( boGender.equalsIgnoreCase("2") ){
    employeeList.add(new Administrator(staffID,name,boGender,ic,address,
    telhome,telhp,fax,email,password,remark,position,sa,department));
    }else if ( boGender.equalsIgnoreCase("3") ){
    employeeList.add(new Manager(staffID,name,boGender,ic,address,
    telhome,telhp,fax,email,password,remark,position,sa,department));
    }else if ( boGender.equalsIgnoreCase("4") ){//lecturer
    Lecturer a = new Lecturer(staffID,name,boGender,ic,address,
    telhome,telhp,fax,email,password,remark,position,sa,department);
    employeeList.add(a);
    }
    JOptionPane.showMessageDialog(null,"Insertion Sucess",
    "Insertion",JOptionPane.INFORMATION_MESSAGE);
    }else JOptionPane.showMessageDialog(null,"Insertion Failed",
    "Insertion",JOptionPane.INFORMATION_MESSAGE);
    }
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    System.out.println(sqlex.toString());
    JOptionPane.showMessageDialog(null,sqlex.toString());
    }
    }

    public void addStudent(String studentID, String name, String boGender,
    String ic,String address,String telhome,
    String telhp,String fax,String email,
    String password,String remark,String intakeid){
    try{
    Statement statement1 = connection.createStatement();
    String valid = "SELECT * FROM Student WHERE studentid ='" +
    studentID + "'";
    ResultSet rs = statement1.executeQuery(valid);
    if ( rs.next()){
    JOptionPane.showMessageDialog(null,"Duplicate Student ID Found!",
    "Error", JOptionPane.ERROR_MESSAGE);
    }
    }catch(SQLException sqlex){}
    try{
    if (validateStudentAction(studentID, name, boGender,ic,address,telhome,telhp,fax,email,
    password,remark,intakeid)){
    Statement statement = connection.createStatement();
    String query = "INSERT INTO Student(studentid,name,gender,ic,address,telhome,telhp,fax,email,password,remark,intakeid) "+
    "VALUES ('" + studentID + "', '" + name + "', '" + boGender + "', '" +
    ic + "', '" + address + "', '" + telhome + "', '" + telhp + "', '" +
    fax + "', '" + email + "', '" + password + "', '" + remark + "', '" +
    intakeid + "')";
    int result = statement.executeUpdate(query);
    if ( result == 1 ){
    studentList.add(new Student(studentID,name,boGender,ic,address,telhome,telhp,fax,
    email,password,remark,intakeid,0));
    JOptionPane.showMessageDialog(null,"Insertion Sucess",
    "Insertion",JOptionPane.INFORMATION_MESSAGE);
    }else{
    JOptionPane.showMessageDialog(null,"Insertion Failed",
    "Insertion",JOptionPane.INFORMATION_MESSAGE);
    }
    }
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    System.out.println(sqlex.toString());
    JOptionPane.showMessageDialog(null,sqlex.toString());
    }
    }

    public void addClassroom(String classroomid,String type,String maxpeople,
    String aircon,String mic,String projector,String computer){
    try{
    Statement statement1 = connection.createStatement();
    String valid = "SELECT * FROM Classroom WHERE classroomID = '" +
    classroomid + "'";
    ResultSet rs = statement1.executeQuery(valid);
    if (rs.next()){
    JOptionPane.showMessageDialog(null, "No Duplicate Classroom ID.", "Error",
    JOptionPane.ERROR_MESSAGE);
    rs.close();
    statement1.close();
    return;
    }
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    JOptionPane.showMessageDialog(null, sqlex.getMessage());
    }
    try{
    if(validateClassroomAction(classroomid,type,maxpeople,aircon,mic,
    projector,computer)){
    Statement statement = connection.createStatement();
    String query = "INSERT INTO Classroom(classroomID, type, maxpeople, aircon, mic, projector, computer) " +
    "VALUES ('" + classroomid + "', '" +
    type + "', '" + maxpeople + "', '" +
    aircon + "', '" + mic + "', '" + projector + "', '" + computer + "')";
    int result = statement.executeUpdate(query);
    if (result == 1){
    JOptionPane.showMessageDialog(null, "Insertion Success",
    "Insertion", JOptionPane.INFORMATION_MESSAGE);
    this.classroomList.add(new Classroom(classroomid,type,maxpeople,aircon,mic,projector,computer));
    }else JOptionPane.showMessageDialog(null, "Insertion Failed");
    }
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    JOptionPane.showMessageDialog(null, sqlex.getMessage());
    }
    }

    public boolean delStaff(String staffID){
    try{
    Statement statement = connection.createStatement();
    String query = "DELETE FROM Staff WHERE staffid ='" + staffID + "'";
    int result = statement.executeUpdate(query);

    if ( result == 1 ){
    JOptionPane.showMessageDialog(null,"Deletion Sucess",
    "Deletion",JOptionPane.INFORMATION_MESSAGE);
    for ( int count = 0; count < employeeList.size(); count++ ){
    Staff temp = (Staff)employeeList.get(count);
    if ( temp.getID().equalsIgnoreCase(staffID.trim())){
    studentList.remove(count);
    }
    }
    return true;
    }else{
    JOptionPane.showMessageDialog(null,"Deletion Failed",
    "Deletion",JOptionPane.INFORMATION_MESSAGE);
    return false;}
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    return false;
    }
    }

    public boolean delStudent(String studentID){
    try{
    Statement statement = connection.createStatement();
    String query = "DELETE FROM Student WHERE studentid ='" + studentID + "'";
    int result = statement.executeUpdate(query);

    if ( result == 1 ){
    JOptionPane.showMessageDialog(null,"Deletion Sucess",
    "Deletion",JOptionPane.INFORMATION_MESSAGE);
    ///delete mark;
    for ( int count = 0; count < studentList.size(); count++ ){
    Student temp = (Student)studentList.get(count);
    if ( temp.getID().equalsIgnoreCase(studentID.trim())){
    studentList.remove(count);
    }
    }
    return true;
    }else{
    JOptionPane.showMessageDialog(null,"Deletion Failed",
    "Deletion",JOptionPane.INFORMATION_MESSAGE);
    return false;
    }
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    JOptionPane.showMessageDialog(null,sqlex.getMessage());
    return false;
    }
    }

    public boolean delClassroom(String classroomid){
    try{
    Statement statement = connection.createStatement();
    String query = "DELETE FROM Classroom WHERE classroomID = '" + classroomid + "'";
    int result = statement.executeUpdate(query);
    if (result == 1){
    JOptionPane.showMessageDialog(null, "Deletion Success", "Insertion", JOptionPane.INFORMATION_MESSAGE);
    for ( int count = 0; count < classroomList.size(); count++ ){
    Classroom temp = (Classroom)classroomList.get(count);
    if ( temp.getClassroomID().equalsIgnoreCase(classroomid.trim())){
    studentList.remove(count);
    }
    }
    }else{
    JOptionPane.showMessageDialog(null, "Deletion Failed", "Deletion", JOptionPane.INFORMATION_MESSAGE);
    return false;
    }
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    JOptionPane.showMessageDialog(null, sqlex.getMessage());
    return false;
    }
    return true;
    }

    private void startConnection(){
    try {
    String url = "jdbc:eek:dbc:eek:op";
    String user = "oop";
    String password = "abc123";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    connection = DriverManager.getConnection(url,user,password);
    System.out.println("Connection Successful");
    getClassroomData();
    getStudentData();
    getEmployeeData();
    }
    catch (ClassNotFoundException cnfex) {
    cnfex.printStackTrace();
    JOptionPane.showMessageDialog(null,"Database Connection Error",
    getUniversityName(),JOptionPane.ERROR_MESSAGE );
    System.exit(1);
    }
    catch (SQLException sqlex) {
    sqlex.printStackTrace();
    JOptionPane.showMessageDialog(null,"Database Connection Error",
    getUniversityName(),JOptionPane.ERROR_MESSAGE );
    System.exit(1);
    }
    catch (Exception ex) {
    ex.printStackTrace();
    JOptionPane.showMessageDialog(null,"Database Connection Error",
    getUniversityName(),JOptionPane.ERROR_MESSAGE );
    System.exit(1);
    }
    }

    continue...
     
  4. Bretenn

    Bretenn Guest

    private void getClassroomData()throws SQLException{
    Statement statement = connection.createStatement();
    String query = "SELECT * FROM classroom";
    ResultSet rs = statement.executeQuery(query);
    if (rs.next()){
    do{
    String a = rs.getString("classroomID").trim();
    String b = rs.getString("type").trim();
    String c = rs.getString("maxPeople");
    boolean d1 = rs.getBoolean("aircon");
    boolean d2 = rs.getBoolean("mic");
    boolean d3 = rs.getBoolean("projector");
    boolean d4 = rs.getBoolean("computer");
    classroomList.add(new Classroom(a,b,c,d1,d2,d3,d4));
    }while(rs.next());
    }
    else{
    JOptionPane.showMessageDialog(null,"Classroom record not found");
    }
    }

    private void getStudentData()throws SQLException{
    Statement statement = connection.createStatement();
    String query = "SELECT * FROM Student";
    ResultSet rs = statement.executeQuery(query);
    if (rs.next()){
    do{
    String a = rs.getString("studentID").trim();
    String b = rs.getString("name").trim();
    String c = rs.getString("gender").trim();
    String d = rs.getString("ic").trim();
    String e = rs.getString("address").trim();
    String f = rs.getString("telHome").trim();
    String g = rs.getString("telHp").trim();
    String h = rs.getString("fax").trim();
    String j = rs.getString("email").trim();
    String k = rs.getString("password").trim();
    String l = rs.getString("remark");
    String m = rs.getString("intakeid").trim();
    double n = rs.getDouble("overallResult");
    studentList.add( new Student(a,b,c,d,e,f,g,h,j,k,l,m,n));
    }while(rs.next());
    }
    else{
    JOptionPane.showMessageDialog(null,"Classroom record not found");
    }
    }

    private void getEmployeeData()throws SQLException{
    Statement statement = connection.createStatement();
    String query = "SELECT * FROM Staff";
    ResultSet rs = statement.executeQuery(query);
    if (rs.next()){
    do{
    String a = rs.getString("staffID");
    String b = rs.getString("name");
    String c = rs.getString("gender");
    String d = rs.getString("ic");
    String e = rs.getString("address");
    String f = rs.getString("telHome");
    String g = rs.getString("telHp");
    String h = rs.getString("fax");
    String j = rs.getString("email");
    String k = rs.getString("password");
    String l = rs.getString("remark");
    String m = rs.getString("grouptype");
    String n = rs.getString("employedas");
    double o = rs.getDouble("salary");
    String p = rs.getString("Department");
    if ( m.equalsIgnoreCase("1"))
    employeeList.add( new Staff(a,b,c,d,e,f,g,h,j,k,l,n,o,p));
    else if (m.equalsIgnoreCase("2"))
    employeeList.add( new Administrator(a,b,c,d,e,f,g,h,j,k,l,n,o,p));
    else if (m.equalsIgnoreCase("3"))
    employeeList.add( new Manager(a,b,c,d,e,f,g,h,j,k,l,n,o,p));
    else employeeList.add( new Lecturer(a,b,c,d,e,f,g,h,j,k,l,n,o,p));
    }while(rs.next());
    }
    else{
    JOptionPane.showMessageDialog(null,"Classroom record not found");
    }
    }



    private boolean validateClassroomAction(String classroomid,String type,
    String maxpeople,String aircon,String mic,String projector,String computer){
    if (classroomid.equalsIgnoreCase("")){
    JOptionPane.showMessageDialog(null, "Classroom ID cannot be blank.", "Error", JOptionPane.ERROR_MESSAGE);
    return false;
    }
    if (classroomid.length() > 6 ){
    JOptionPane.showMessageDialog(null, "Classroom ID cannot be more than 6 character.", "Error", JOptionPane.ERROR_MESSAGE);
    return false;
    }
    return true;
    }

    public void modifyStudent(String studentID, String name, String boGender,
    String ic,String address,String telhome,
    String telhp,String fax,String email,
    String password,String remark,String intakeid){

    try{
    if ( validateStudentAction(studentID, name, boGender,ic,address,telhome,telhp,fax,email,
    password,remark,intakeid)){

    Statement statement = connection.createStatement();
    String query = "UPDATE Student SET " +
    "name ='" + name + "', " +
    "gender ='" + boGender + "', "+
    "ic ='" + ic + "', "+
    "address ='" + address + "', "+
    "telhome ='" + telhome + "', "+
    "telhp ='" + telhp + "', "+
    "fax ='" + fax + "', "+
    "email ='" + email + "', "+
    "password ='" + password + "', "+
    "remark ='" + remark + "', "+
    "intakeid ='" + intakeid + "' "+
    "WHERE studentid ='" + studentID + "' ";
    int result = statement.executeUpdate(query);
    if ( result == 1 ){
    JOptionPane.showMessageDialog(null,"Modify Sucess",
    "Modify",JOptionPane.INFORMATION_MESSAGE);
    for ( int count = 0; count < studentList.size(); count++ ){
    Student temp = (Student)studentList.get(count);
    if ( temp.getID().equalsIgnoreCase(studentID.trim())){
    temp.setName(name);
    temp.setGender(boGender);
    temp.setIC(ic);
    temp.setAddress(address);
    temp.setTelHome(telhome);
    temp.setTelHp(telhp);
    temp.setFax(fax);
    temp.setEmail(email);
    temp.setPassword(password);
    temp.setRemark(remark);
    temp.setIntake(new Intake(intakeid,studentID));
    temp.startConnection();
    }
    }
    }else JOptionPane.showMessageDialog(null,"Modify Failed",
    "Modify",JOptionPane.INFORMATION_MESSAGE);
    }
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    }
    }

    public void modifyClassroom(String classroomid,String type,String maxpeople,
    String aircon,String mic,String projector,String computer){
    try{
    Statement statement = connection.createStatement();
    String query = "UPDATE Classroom SET " +
    "classroomID = '" + classroomid +
    "', type = '" + type +
    "', maxpeople = '" + maxpeople +
    "', aircon = '" + aircon +
    "', mic = '" + mic +
    "', projector = '" + projector +
    "', computer = '" + computer +
    "' WHERE classroomID = '" + classroomid + "'";

    int result = statement.executeUpdate(query);
    if (result == 1){
    JOptionPane.showMessageDialog(null, "Modification Success", "Modification", JOptionPane.INFORMATION_MESSAGE);
    for ( int count = 0; count < studentList.size(); count++ ){
    Classroom temp = (Classroom)classroomList.get(count);
    if ( temp.getClassroomID().equalsIgnoreCase(classroomid.trim())){
    temp.setMaxPeople(maxpeople);
    if ( aircon.equalsIgnoreCase("1"))
    temp.addEquipment("aircon");
    if ( mic.equalsIgnoreCase("1"))
    temp.addEquipment("mic");
    if (projector.equalsIgnoreCase("1"))
    temp.addEquipment("projector");
    if (computer.equalsIgnoreCase("1"))
    temp.addEquipment("computer");
    }
    }
    }else JOptionPane.showMessageDialog(null, "Modification Failed", "Modification", JOptionPane.INFORMATION_MESSAGE);

    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    JOptionPane.showMessageDialog(null, sqlex.getMessage());
    }
    }


    public void modifyStaff(String staffID,String name,String boGender,
    String ic,String address,String telhome,
    String telhp,String fax,String email,
    String password,String remark,
    String boGroupType,String position,String salary,
    String department){
    try{
    if ( validateStaffAction(staffID,name,boGender,ic,address,telhome,telhp,fax,email,
    password,remark,boGroupType,position,salary,department)){

    Statement statement = connection.createStatement();
    String query = "UPDATE Staff SET " +
    "name ='" + name + "', " +
    "gender ='" + boGender + "', "+
    "ic ='" + ic + "', "+
    "address ='" + address + "', "+
    "telhome ='" + telhome + "', "+
    "telhp ='" + telhp + "', "+
    "fax ='" + fax + "', "+
    "email ='" + email + "', "+
    "password ='" + password + "', "+
    "remark ='" + remark + "', "+
    "grouptype ='" + boGroupType + "', "+
    "employedas ='" + position + "', "+
    "salary ='" + salary + "', "+
    "department ='" + department + "' "+
    "WHERE staffid ='" + staffID + "' ";
    int result = statement.executeUpdate(query);
    if ( result == 1 ){
    JOptionPane.showMessageDialog(null,"Modify Sucess",
    "Modify",JOptionPane.INFORMATION_MESSAGE);
    for ( int count = 0; count < employeeList.size(); count++ ){
    Staff temp = (Staff)employeeList.get(count);
    if ( temp.getID().equalsIgnoreCase(staffID.trim())){
    temp.setName(name);
    temp.setGender(boGender);
    temp.setIC(ic);
    temp.setAddress(address);
    temp.setTelHome(telhome);
    temp.setTelHp(telhp);
    temp.setFax(fax);
    temp.setEmail(email);
    temp.setPassword(password);
    temp.setRemark(remark);
    temp.setEmployedAs(position);
    temp.setSalary(Double.parseDouble(salary));
    temp.setDepartment(department);
    if ( boGroupType.equalsIgnoreCase("4")){
    Lecturer temp1 = (Lecturer)temp;
    temp1.startConnection();
    }
    }
    }
    }else JOptionPane.showMessageDialog(null,"Modify Failed",
    "Modify",JOptionPane.INFORMATION_MESSAGE);
    }
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    }
    }

    :confused:
     
  5. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Woha! That's way to much code!
    On line 81 in LoginDialog.java something happens. If I'm not misstaken you run the SQL query there (some time since I did Java). And you are using to few parametres. The trace points to where the fault is. Just follow the trace.