jsp的一段查询数据库代码总是空指针错误怎么回事啊?
<%Stringsql="select*from`customer`";Connectionconn=DB.getCon();Statementstmt=DB.getSt...
<%
String sql="select * from `customer`";
Connection conn=DB.getCon();
Statement stmt=DB.getStmt(conn);
ResultSet rs=DB.getRs(stmt,sql);
%>
jsp代码如上:
javabean代码如下:(customer是我建的一个表)
public class DB {
public static Connection getCon() {
Connection conn=null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/rent?user=root&password=cuiruikai");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static Statement getStmt(Connection conn){
Statement stmt=null;
try {
stmt =conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return stmt;
}
public static ResultSet getRs(Statement stmt,String sql){
ResultSet rs = null;
try {
rs=stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
}
怎么回事啊老是说空指针错误!!?? 展开
String sql="select * from `customer`";
Connection conn=DB.getCon();
Statement stmt=DB.getStmt(conn);
ResultSet rs=DB.getRs(stmt,sql);
%>
jsp代码如上:
javabean代码如下:(customer是我建的一个表)
public class DB {
public static Connection getCon() {
Connection conn=null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/rent?user=root&password=cuiruikai");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static Statement getStmt(Connection conn){
Statement stmt=null;
try {
stmt =conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return stmt;
}
public static ResultSet getRs(Statement stmt,String sql){
ResultSet rs = null;
try {
rs=stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
}
怎么回事啊老是说空指针错误!!?? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询