我才学java web几天,依照教材上敲了一些程序,可是在eclipse中运行报错。明明和教材上一模一样,为什么我这个就报错了呢?
我学这个时间还不太久,我按教材上敲了这些程,但是eclipse报错,很是烦恼,和书上一模一样的,怎么就错了呢?
HTTP Status 500 -
--------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.study.DAO.studentDAO.studenname(studentDAO.java:36)
com.study.servlet.studentservlet.doPost(studentservlet.java:43)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
以下是我的两个程序
-------------------------------------
package com.study.DAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.student.bean.student;
public class studentDAO {
private Connection con=null;
public void initCon(){
try{
Class.forName("com.jdbc.mysql.Driver");
String url="jdbc:mysql://localhost:3306/lianxi";
con=DriverManager.getConnection(url,"root","root");
}
catch(Exception ex){ex.printStackTrace();}
}
public ArrayList studenname(String stuname){
this.initCon();
ArrayList stud=new ArrayList();
String sql="SELECT stuid,stuname,stusex,stuphone,stuplace FROM student WHERE stuname like '%"+stuname+"%'";//select * from student where stuname like '%"+stuname+" %'
try {
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
student stu=new student();
stu.setStuid(rs.getString("stuid"));
stu.setStuname(rs.getString("stuname"));
stu.setStusex(rs.getString("stusex"));
stu.setStuphone(rs.getString("stuphone"));
stu.setStuplace(rs.getString("stuplace"));
stud.add(stu);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
this.closeCon();
}
return stud;
}
public void closeCon(){