求大神帮我,pstmt = conn.prepareStatement(sql);空指针,sql是能够运行的
packageDaoimpl;importjava.sql.SQLException;importDao.BaseDao;importDao.Login;publiccl...
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;
/**
* 数据库连接方法
*/ 展开
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;
/**
* 数据库连接方法
*/ 展开
威孚半导体技术
2024-08-19 广告
2024-08-19 广告
威孚(苏州)半导体技术有限公司是一家专注生产、研发、销售晶圆传输设备整机模块(EFEM/SORTER)及核心零部件的高科技半导体公司。公司核心团队均拥有多年半导体行业从业经验,其中技术团队成员博士、硕士学历占比80%以上,依托丰富的软件底层...
点击进入详情页
本回答由威孚半导体技术提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询