pstmt = conn.prepareStatement(sql);中报空指针错误,sql是能运行的
----------------------------------------------------------------------------------pac...
----------------------------------------------------------------------------------
package Daoimpl;
import java.sql.SQLException;
import Dao.BaseDao;
import Dao.Login;
public class Loginimpl extends BaseDao implements Login{
public void Login(String a,String b) {
BaseDao base=new BaseDao();
base.openConnection();
String sql = "select * from login where username='a' and userpass='b';";
try {
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(!rs.next()){
System.out.print("<script>windows.location.href='/index.jsp';</script>");
}
System.out.print("<script>windows.location.href='/menu.jsp';</script>");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
base.closeResource();
}
}
public void Dropservice() {
// TODO Auto-generated method stub
}
}
package Dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseDao {
protected Connection conn = null;
protected PreparedStatement pstmt = null;
protected ResultSet rs = null;
/**
* 数据库连接方法
*/ 展开
package Daoimpl;
import java.sql.SQLException;
import Dao.BaseDao;
import Dao.Login;
public class Loginimpl extends BaseDao implements Login{
public void Login(String a,String b) {
BaseDao base=new BaseDao();
base.openConnection();
String sql = "select * from login where username='a' and userpass='b';";
try {
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(!rs.next()){
System.out.print("<script>windows.location.href='/index.jsp';</script>");
}
System.out.print("<script>windows.location.href='/menu.jsp';</script>");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
base.closeResource();
}
}
public void Dropservice() {
// TODO Auto-generated method stub
}
}
package Dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BaseDao {
protected Connection conn = null;
protected PreparedStatement pstmt = null;
protected ResultSet rs = null;
/**
* 数据库连接方法
*/ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询