0

Hey, I've come across an error in my school project. I'm creating a college registration web app. The jsp displays a list of available classes with checkboxes to check the ones you would like to register for. I've been running it in debug mode and it throws an exception at the executeUpdate() method. I'm not sure what could be wrong. Its getting the proper values as far as the StudentID, ClassID, and Payment variables. I'm not sure what I should put up as far as my go goes but here is where the error is occuring.

package data;

import java.sql.*;

import business.Schedule;

public class RegisterClasses
{
    public static Schedule register(String id, String[] regClasses)
    {

        Schedule schedule = RetrieveClassesDAO.getClasses(regClasses);

        Connection connection = ConnectionManager.getConnection();
        PreparedStatement statement = null;

        String query = "INSERT INTO registeredcourses(ClassID, StudentID, Payment) VALUES(?, ?, ?)";

        try
        {
            statement = connection.prepareStatement(query);

            for(int i = 0; i < regClasses.length; i++)
            {
                statement.setString(1, regClasses[i]);
                statement.setString(2, id);
                statement.setString(3, "0");
                int e = statement.executeUpdate();
            }

        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }

        return schedule;
    }
}

Edited by jmw5598: none

3
Contributors
3
Replies
17
Views
4 Years
Discussion Span
Last Post by radhakrishna.p
0

please describe the exception.What excetion you are getting,then only we can help you to solve it.

0

Well, when I run the app it runs fine without crashing, but nothing was getting stored in the database, so I stepped through it in debugg mode in netbeans and found that it's not executing the line

int e = statement.executeUpdate();

When it attempts to process this line it fails the try block and jumps to the catch block and prints the stacktrace for the SQLException. All the other lines above it are processed fine.

this is the table that I'm trying to insert into.

CREATE  TABLE `collegeservices`.`registeredcourses` (
  `ClassID` VARCHAR(7) NOT NULL ,
  `StudentID` VARCHAR(45) NOT NULL ,
  `Payment` BIT(1) NULL DEFAULT b'0' ,
  PRIMARY KEY (`ClassID`, `StudentID`) );
0

hai jmw5598,

there are plenty of reasons for coming SQLException in order to connect with databse.itrs not easy to trace out by just specifying "SQLException"

could you please post entire printStackTrace() details here?

so that it will be easy for us to help you...

happy coding..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.