无头的例外

时间:2017-01-01 17:56:43

标签: netbeans-8

我想问一个解决我问题的方法:

HTTP Status 500 - Internal Server Error

type Exception report

message Internal Server Error

description The server encountered an internal error that prevented it from      
fulfilling this request.

exception
java.awt.HeadlessException

note The full stack traces of the exception and its root causes are available   
in the GlassFish Server Open Source Edition 4.1.1 logs.

GlassFish Server Open Source Edition 4.1.1

数据库中有几个表,但是当我需要从“Student”表中获取记录时,它会一直显示此错误。

域名文件:

package domain;

import java.io.Serializable;
import java.util.Objects;

public class Student implements Serializable {
private String studID;
private String studName;
private int studIC;
private String gender;
private String address;
private int contactNo;

public Student(){}

public Student(String studID){
    this.studID = studID;
}

public Student(String studID, String studName, int studIC, String gender, String address, int contactNo){
    this.studID = studID;
    this.studName = studName;
    this.studIC = studIC;
    this.gender = gender;
    this.address = address;
    this.contactNo = contactNo;
}

public String getStudID(){
    return studID;
}

public void setStudID(String studID){
    this.studID = studID;       
}

public String getStudName(){
    return studName;
}

public void setStudName(String studName){
    this.studName = studName;
}

public int getStudIC(){
    return studIC;
}

public void setStudIC(int studIC){
    this.studIC = studIC;
}

public String getGender(){
    return gender;
}

public void setGender(String gender){
    this.gender = gender;
}

public String getAddress(){
    return address;
}

public void setAddress(String address){
    this.address = address;
}

public int getContactNo(){
    return contactNo;
}

public void setContactNo(int contactNo){
    this.contactNo = contactNo;
}

}

da file:

package da;

import domain.Student;
import java.sql.*;
import javax.swing.*;


public class StudentDA {
private String host = "jdbc:derby://localhost:1527/hostelDB";
private String user = "nbuser";
private String password = "nbuser";
private String tableName = "Student";
private Connection conn;
private PreparedStatement stmt;

public StudentDA(){
    createConnection();
}

public void addRecord(Student student) {
    String insertStr = "INSERT INTO " + tableName + " VALUES(?, ?, ?, ?, ?, ?)";
    try {
        stmt = conn.prepareStatement(insertStr);
        stmt.setString(1, student.getStudID());
        stmt.setString(2, student.getStudName());
        stmt.setInt(3, student.getStudIC());
        stmt.setString(4, student.getGender());
        stmt.setString(5, student.getAddress());
        stmt.setInt(6, student.getContactNo());
        stmt.executeUpdate();
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
    }
}

public Student getRecord(String studID) {
    String queryStr = "SELECT * FROM " + tableName + " WHERE StudentID = ?";
    Student student = null;
    try {
        stmt = conn.prepareStatement(queryStr);
        stmt.setString(1, studID);
        ResultSet rs = stmt.executeQuery();

        if (rs.next()) {
            student = new Student(studID, rs.getString("StudentName"), rs.getInt("StudentIC"), rs.getString("Gender"), rs.getString("Address"), rs.getInt("ContactNo"));

        }
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
    }
    return student;
}

private void createConnection() {
    try {
        Class.forName("org.apache.derby.jdbc.ClientDriver");
        conn = DriverManager.getConnection(host, user, password);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
    }
}

private void shutDown() {
    if (conn != null) {
        try {
            conn.close();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
        }
    }
}

}                    

servlet:

String studID = request.getParameter("studID");
Student stud = studDA.getRecord(studID);
out.println(stud);

0 个答案:

没有答案