我已经开发了下面的程序,但是它抛出了空指针异常。
下面是模型类..
public class Circle {
private int Id;
public Circle(int id, String name) {
super();
Id = id;
this.name = name;
}
private String name;
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
下面是dao类..
public class jdbcdaoimpl {
public Circle getCircle(int circleId)
{
Circle circle = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","saral","saral");
PreparedStatement stmt=con.prepareStatement("select * from CIRCLE where id = ?");
stmt.setInt(1,circleId);
ResultSet rset=stmt.executeQuery();
while(rset.next())
{
circle= new Circle(circleId, rset.getString("name") );
}
rset.close();
stmt.close();
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return circle;
}
}
最后是主要课程..
public class jdbcDemo {
public static void main(String[] args) {
Circle c = new jdbcdaoimpl().getCircle(1);
System.out.println(c.getName());
}
}
请告知在执行主类时抛出空指针异常。