急!java web课程设计中,连接数据库用户名和密码验证问题,输入密码跳转不到huanying1.jsp

急!java web课程设计中,连接数据库用户名和密码验证问题,输入密码跳转不到huanying1.jsp,第1张

String sql = "select  from reader where readerId= and readerPwd=";

PreparedStatement pstmt = connprepareStatement(sql);

pstmtsetString(1,user);

pstmtsetString(2,pass);

ResultSet rs = pstmtexecuteQuery();

if(rsnext()){

flag = true;

}

您的这一块改一下吧,改为这样的:

String sql = "select count() from reader where readerId= and readerPwd=";

PreparedStatement pstmt = connprepareStatement(sql);

pstmtsetString(1,user);

pstmtsetString(2,pass);

ResultSet rs = pstmtexecuteQuery();

rsnext();

if(rsgetInt()!=0){

flag = true;

}

100分想让别人给你单独写一个程序应该是没人给你写的,还是参考一下别人类似的代码吧,我大二的时候写过一个系统:个人财务管理系统你拿去参考下吧

//登录类:

import javaxswing;

import javaawt;

import javaawtevent;

import javaworkjdbc;

public class Login extends JFrame implements ActionListener{

public static void main(String ary[]){

new Login("home financial management system");

}

private JButton login=new JButton("登陆");

private JButton register=new JButton("注册");

private JButton cancel=new JButton("取消");

private JPanel panelsouth=new JPanel(new FlowLayout(new FlowLayout()CENTER));

private JPanel paneluser=new JPanel(new FlowLayout(new FlowLayout()CENTER));

private JPanel panelpassword=new JPanel(new FlowLayout(new FlowLayout()CENTER));

private JPanel panelcenter=new JPanel(new GridLayout(2,1));

private JLabel user=new JLabel("用户名: ");

private JLabel title=new JLabel(" 家庭财务管理系统");

private JLabel password=new JLabel("密 码: ");

private JTextField userT=new JTextField(10);

private JPasswordField passwordT=new JPasswordField(10);

public Login(String title){

super(title);

thissetResizable(false);

thisaddWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){Systemexit(0);}

});

thissetBounds(300,250,350,250);

frameLayout();

addListener();

thissetVisible(true);

}

public void frameLayout(){

panelsouthadd(login);

panelsouthadd(register);

panelsouthadd(cancel);

thisgetContentPane()add(panelsouth,BorderLayoutSOUTH);

paneluseradd(user);

paneluseradd(userT);

panelpasswordadd(password);

panelpasswordadd(passwordT);

panelcenteradd(paneluser);

panelcenteradd(panelpassword);

thisgetContentPane()add(panelcenter,BorderLayoutCENTER);

titlesetFont(new Font("黑体",FontBOLD,30));

thisgetContentPane()add(title,BorderLayoutNORTH);

}

public void addListener(){

loginaddActionListener(this);

canceladdActionListener(this);

registeraddActionListener(this);

passwordTaddActionListener(this);

}

public void actionPerformed(ActionEvent e) {

if(egetSource()==login||egetSource()==passwordT){

String use=userTgetText();

String pass=new String(passwordTgetPassword());

Operate operate=new Operate();

if(operatelogin(use, pass)){

new MainFrame(userTgetText());

thissetVisible(false);

}else{

JOptionPaneshowMessageDialog(this, "用户名或密码不正确");

}

}

if(egetSource()==register){

String info="";

String use=userTgetText();

String pass=new String(passwordTgetPassword());

Operate operate=new Operate();

if(operateregister(use, pass)){

info="注册成功";

}else{

info="注册失败";

}

JOptionPaneshowMessageDialog(this, info);

}

if(egetSource()==cancel){

Systemexit(0);

}

}

}

//主柜架类:

import javaawtevent;

import javaworkbeanSysBean;

import javaworkjdbc;

import javaxswing;

import javaawt;

import javautilVector;

public class MainFrame extends JFrame implements ActionListener{

private boolean mode=true;

private JTable tabel=null;

private JPanel south=new JPanel(new FlowLayout(new FlowLayout()CENTER));

private JPanel north=new JPanel(new FlowLayout(new FlowLayout()CENTER));

private JLabel begin=new JLabel("从:");

private JLabel beginyear=new JLabel("年");

private JLabel beginmonth=new JLabel("月");

private JLabel beginday=new JLabel("日");

private JLabel end=new JLabel("到:");

private JLabel endyear=new JLabel("年");

private JLabel endmonth=new JLabel("月");

private JLabel endday=new JLabel("日");

private JComboBox beginyearB=new JComboBox();

private JComboBox beginmonthB=new JComboBox();

private JComboBox begindayB=new JComboBox();

private JComboBox endyearB=new JComboBox();

private JComboBox endmonthB=new JComboBox();

private JComboBox enddayB=new JComboBox();

private JButton add=new JButton("添加记录");

private JButton delete=new JButton("删除记录");

private JButton update=new JButton("更新记录");

private JButton cancel=new JButton("退出系统");

private JButton refresh=new JButton("刷新记录");

private JButton select=new JButton("查询记录");

String info[][]=null;

private String[] field={"ID","spending","epecificSpending","income","epecificIncome","total","journal","date"};

private String use=null;

public MainFrame(String name){

use=name;

thissetTitle("home financial management system");

thisaddWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

Systemexit(0);

}

});

thissetSize(700,500);

thissetResizable(false);

thissetLocationRelativeTo(null);

frameLayout();

addListener();

thissetVisible(true);

}

public void editnorth(){

for(int i=1950;i<=2050;i++){

beginyearBaddItem(""+i);

endyearBaddItem(""+i);

}

for(int i=1;i<=12;i++){

beginmonthBaddItem(""+i);

endmonthBaddItem(""+i);

}

northadd(begin); northadd(beginyear); northadd(beginyearB);

northadd(beginmonth);northadd(beginmonthB);

northadd(beginday); northadd(begindayB);

northadd(end); northadd(endyear); northadd(endyearB);

northadd(endmonth); northadd(endmonthB);

northadd(endday); northadd(enddayB); northadd(select);

}

Vector<SysBean> vector=new Operate()select(use);

public void editJTable(){

info=new String[200][8];

info[0]=new String[]{"","","","","","","",""};

for(int i=1;i<vectorsize()+1;i++){

info[i][0]=""+vectorget(i-1)getID();

info[i][1]=""+vectorget(i-1)getSpending();

info[i][2]=""+vectorget(i-1)getEpecificSpending();

info[i][3]=""+vectorget(i-1)getIncome();

info[i][4]=""+vectorget(i-1)getEpecificIncome();

info[i][5]=""+vectorget(i-1)getTotal();

info[i][6]=""+vectorget(i-1)getJournal();

info[i][7]=""+vectorget(i-1)getDate();

}

}

public void frameLayout(){

southadd(add);

southadd(delete);

southadd(update);

southadd(refresh);

southadd(cancel);

editnorth();

editJTable();

tabel=new JTable(info,field);

tabelsetAutoResizeMode(tabelAUTO_RESIZE_SUBSEQUENT_COLUMNS);

thisgetContentPane()add(new JScrollPane(tabel),BorderLayoutCENTER);

thisgetContentPane()add(south,BorderLayoutSOUTH);

thisgetContentPane()add(north,BorderLayoutNORTH);

}

public void addListener(){

addaddActionListener(this);

deleteaddActionListener(this);

updateaddActionListener(this);

canceladdActionListener(this);

refreshaddActionListener(this);

selectaddActionListener(this);

beginmonthBaddActionListener(this);

beginyearBaddActionListener(this);

endyearBaddActionListener(this);

endmonthBaddActionListener(this);

}

public void removeB(){

beginyearBremoveAll();

beginmonthBremoveAll();

begindayBremoveAll();

endyearBremoveAll();

endmonthBremoveAll();

enddayBremoveAll();

}

public void removeListener(){

addremoveActionListener(this);

deleteremoveActionListener(this);

updateremoveActionListener(this);

cancelremoveActionListener(this);

refreshremoveActionListener(this);

selectremoveActionListener(this);

beginmonthBremoveActionListener(this);

endmonthBremoveActionListener(this);

beginyearBremoveActionListener(this);

endyearBremoveActionListener(this);

}

public void actionPerformed(ActionEvent e) {

if(egetSource()==add){

addSource();

}if(egetSource()==delete){

deleteSource();

}if(egetSource()==update){

updateSource();

}if(egetSource()==select){

selectSource();

}if(egetSource()==cancel){

Systemexit(0);

}if(egetSource()==refresh){

refreshSource();

}if(egetSource()==beginmonthB||egetSource()==beginyearB){

beginmonthBSource();

}if(egetSource()==endmonthB||egetSource()==endyearB){

endmonthBSource();

}

}

public void refreshSource(){

//beginyearBremoveAll();

//beginmonthBremoveAll();

//endyearBremoveAll();

//endmonthBremoveAll();

frameLayout();

thissetVisible(true);

}

public void deleteSource(){

String info="";

try{

int ID=IntegerparseInt(((String)tabelgetValueAt(0, 0))trim());

if(new Operate()delete(ID, use)){

info="删除成功";

}else{

info="删除失败";

}

}catch(Exception e){

info="请正确输入数据";

}

JOptionPaneshowMessageDialog(this,info);

}

public void selectSource(){

String byear=(String)beginyearBgetSelectedItem();

String bmonth=(String)beginmonthBgetSelectedItem();

String bday=(String)begindayBgetSelectedItem();

String eyear=(String)endyearBgetSelectedItem();

String emonth=(String)endmonthBgetSelectedItem();

String eday=(String)enddayBgetSelectedItem();

if(""equals(bday)){

bday="01";

}if(""equals(eday)){

eday="01";

}

String beginDate=byear+"-"+bmonth+"-"+bday;

String endDate=eyear+"-"+emonth+"-"+eday;

vector=new Operate()selectDay(use, javasqlDatevalueOf(beginDate), javasqlDatevalueOf(endDate));

refreshSource();

}

public void beginmonthBSource(){

int byear=IntegerparseInt((String)beginyearBgetSelectedItem());

int bmonth=IntegerparseInt((String)beginmonthBgetSelectedItem());

removeB();

boolean yn=false;

if((byear%4==0&&byear%100!=0)||(byear%100==0&&byear%400==0)){

yn=true;

}

for(int i=1;i<=31;i++){

if(bmonth==2){

if(yn){

if(i<=28){

begindayBaddItem(""+i);

}

}else{

if(i<=29){

begindayBaddItem(""+i);

}

}

}else{

if(bmonth==1||bmonth==3||bmonth==5||bmonth==7||bmonth==8||bmonth==10||bmonth==12){

begindayBaddItem(""+i);

}else{

if(i<=30){

begindayBaddItem(""+i);

}

}

}

}

}

public void endmonthBSource(){

int eyear=IntegerparseInt((String)endyearBgetSelectedItem());

int emonth=IntegerparseInt((String)endmonthBgetSelectedItem());

boolean yn=false;

removeB();

if((eyear%4==0&&eyear%100!=0)||(eyear%100==0&&eyear%400==0)){

yn=true;

}

for(int i=1;i<=31;i++){

if(emonth==2){

if(yn){

if(i<=28){

enddayBaddItem(""+i);

}

}

}else{

if(emonth==1||emonth==3||emonth==5||emonth==7||emonth==8||emonth==10||emonth==12){

enddayBaddItem(""+i);

}else{

if(i<=30){

enddayBaddItem(""+i);

}

}

}

}

Systemoutprint("haah");

}

public void updateSource(){

String info=null;

boolean model=true;

String ID=((String)tabelgetValueAt(0,0))trim();

String spend=((String)tabelgetValueAt(0,1))trim();

String epecificSpending=(String)tabelgetValueAt(0, 2);

String come=((String)tabelgetValueAt(0, 3))trim();

String epecificIncome=(String)tabelgetValueAt(0, 4);

String journal=(String)tabelgetValueAt(0, 6);

try{

int id=IntegerparseInt(ID);

float spending=FloatparseFloat(spend);

float income=FloatparseFloat(come);

tabelsetValueAt(""+(income-spending), 0, 4);

SysBean sysbean=new SysBean();

sysbeansetName(use);

sysbeansetID(id);

sysbeansetSpending(spending);

sysbeansetEpecificSpending(epecificSpending);

sysbeansetIncome(income);

sysbeansetEpecificIncome(epecificIncome);

sysbeansetJournal(journal);

model=new Operate()update(sysbean);

if(model){

info="更新成功!";

tabelsetValueAt("", 0,0);

tabelsetValueAt("", 0,1);

tabelsetValueAt("", 0,2);

tabelsetValueAt("", 0,3);

tabelsetValueAt("", 0,4);

tabelsetValueAt("", 0,5);

tabelsetValueAt("", 0,6);

}else{

info="更新失败!";

}

}catch(Exception o){

info="请正确输入数据!";

}

JOptionPaneshowMessageDialog(this, info);

}

public void addSource(){

String info=null;

boolean model=true;

String spend=((String)tabelgetValueAt(0,1))trim();

String epecificSpending=(String)tabelgetValueAt(0, 2);

String come=((String)tabelgetValueAt(0, 3))trim();

String epecificIncome=(String)tabelgetValueAt(0, 4);

String journal=(String)tabelgetValueAt(0, 6);

try{

float spending=FloatparseFloat(spend);

float income=FloatparseFloat(come);

tabelsetValueAt(""+(income-spending), 0, 4);

SysBean sysbean=new SysBean();

sysbeansetName(use);

sysbeansetSpending(spending);

sysbeansetEpecificSpending(epecificSpending);

sysbeansetIncome(income);

sysbeansetEpecificIncome(epecificIncome);

sysbeansetJournal(journal);

model=new Operate()add(sysbean);

if(model){

info="添加成功!";

tabelsetValueAt("", 0,0);

tabelsetValueAt("", 0,1);

tabelsetValueAt("", 0,2);

tabelsetValueAt("", 0,3);

tabelsetValueAt("", 0,4);

tabelsetValueAt("", 0,5);

tabelsetValueAt("", 0,6);

}else{

info="添加失败!";

}

}catch(Exception o){

info="请正确输入数据!";

}

JOptionPaneshowMessageDialog(this, info);

}

}

*** 作类:

import javasql;

import javautil;

import javaworkbean;

public class Operate {

Connection conn=null;

PreparedStatement pstmt=null;

ResultSet rs=null;

String sql=null;

public Vector<SysBean> selectDay(String name,javasqlDate beginDate,javasqlDate endDate){

Vector<SysBean> vector=new Vector<SysBean>();

Systemoutprintln("selectDay"+" "+beginDate+" "+endDate);

init();

sql="select from info where name= and date between and ";

pstmt=DataBaseConnectiongetpStmt(conn, sql);

try {

pstmtsetString(1, name);

pstmtsetDate(2, beginDate);

pstmtsetDate(3, endDate);

rs=pstmtexecuteQuery();

while(rsnext()){

SysBean sysbean=new SysBean();

sysbeansetID(rsgetInt("ID"));

sysbeansetName(rsgetString("name"));

sysbeansetSpending(rsgetFloat("spending"));

sysbeansetEpecificSpending(rsgetString("epecificSpending"));

sysbeansetIncome(rsgetFloat("income"));

sysbeansetEpecificIncome(rsgetString("epecificIncome"));

sysbeansetTotal(rsgetFloat("total"));

sysbeansetJournal(rsgetString("journal"));

sysbeansetDate(rsgetDate("date"));

sysbeansetID(rsgetInt("ID"));

Systemoutprintln("sysbeangetname= "+sysbeangetDate());

vectoradd(sysbean);

}

} catch (SQLException e) {

eprintStackTrace();

}

close();

return vector;

}

public void init(){

conn=DataBaseConnectiongetConn();

}

public void close(){

if(rs!=null){

DataBaseConnectioncloseRs(rs);

}

DataBaseConnectionclosePstmt(pstmt);

DataBaseConnectioncloseConn(conn);

}

public boolean login(String user,String password){

init();

boolean login=false;

sql="select from ruse where name= and password=";

pstmt=DataBaseConnectiongetpStmt(conn, sql);

try {

pstmtsetString(1, user);

pstmtsetString(2, password);

rs=pstmtexecuteQuery();

if(rsnext()){

login=true;

}

} catch (SQLException e) {

eprintStackTrace();

}

close();

return login;

}

public Vector<SysBean> select(String user){

Vector<SysBean> vector=new Vector<SysBean>();

init();

sql="select from info where name=";

pstmt=DataBaseConnectiongetpStmt(conn, sql);

try {

pstmtsetString(1, user);

rs=pstmtexecuteQuery();

while(rsnext()){

SysBean sysbean=new SysBean();

sysbeansetID(rsgetInt("ID"));

sysbeansetName(rsgetString("name"));

sysbeansetSpending(rsgetFloat("spending"));

sysbeansetEpecificSpending(rsgetString("epecificSpending"));

sysbeansetIncome(rsgetFloat("income"));

sysbeansetEpecificIncome(rsgetString("epecificIncome"));

sysbeansetTotal(rsgetFloat("total"));

sysbeansetJournal(rsgetString("journal"));

sysbeansetDate(rsgetDate("date"));

sysbeansetID(rsgetInt("ID"));

vectoradd(sysbean);

}

} catch (SQLException e) {

eprintStackTrace();

}

close();

return vector;

}

public boolean add(SysBean sysbean){

boolean model=true;

init();

sql="insert into info(name,spending,epecificSpending,income," +

"epecificIncome,journal,date) values(,,,,,,)";

pstmt=DataBaseConnectiongetpStmt(conn, sql);

try {

pstmtsetString(1, sysbeangetName());

pstmtsetFloat(2, sysbeangetSpending());

pstmtsetString(3, sysbeangetEpecificSpending());

pstmtsetFloat(4, sysbeangetIncome());

pstmtsetString(5, sysbeangetEpecificIncome());

pstmtsetString(6, sysbeangetJournal());

pstmtsetDate(7, new javasqlDate(new javautilDate()getTime()));

pstmtexecuteUpdate();

} catch (SQLException e) {

eprintStackTrace();

model=false;

}

close();

return model;

}

public boolean delete(int ID,String use){

boolean model=true;

sql="delete from info where ID= and name=";

init();

pstmt=DataBaseConnectiongetpStmt(conn, sql);

try {

pstmtsetInt(1, ID);

pstmtsetString(2, use);

pstmtexecuteUpdate();

} catch (SQLException e) {

eprintStackTrace();

model=false;

}

close();

return model;

}

public boolean update(SysBean sysbean){

boolean model=true;

sql="update info set spending=," +

"epecificSpending=,income=,epecificIncome=,journal= where ID= and name=";

init();

pstmt=DataBaseConnectiongetpStmt(conn, sql);

try{

pstmtsetFloat(1, sysbeangetSpending());

pstmtsetString(2, sysbeangetEpecificSpending());

pstmtsetFloat(3, sysbeangetIncome());

pstmtsetString(4, sysbeangetEpecificIncome());

pstmtsetString(5, sysbeangetJournal());

pstmtsetInt(6, sysbeangetID());

pstmtsetString(7, sysbeangetName());

pstmtexecuteUpdate();

}catch(Exception e){

model=false;

}

return model;

}

public boolean register(String wm,String password){

boolean model=true;

sql="insert into ruse values(,)";

init();

pstmt=DataBaseConnectiongetpStmt(conn, sql);

try{

pstmtsetString(1,wm);

pstmtsetString(2,password);

pstmtexecuteUpdate();

}catch(SQLException e){

model=false;

}

return model;

}

}

//数据库连接类:

import javasql;

public class DataBaseConnection {

static{

//2005

//String DBDRIVER="commicrosoftjdbcsqlserverSQLServerDriver";//2000

}

public static Connection getConn(){

String DBDRIVER="commicrosoftsqlserverjdbcSQLServerDriver";

String DBURL="jdbc:sqlserver://localhost:1433;DatabaseName=cwgl";

Connection conn=null;

try {

ClassforName(DBDRIVER);

conn=DriverManagergetConnection(DBURL,"sa","1");

} catch (Exception e) {

eprintStackTrace();

}

return conn;

}

public static void closeConn(Connection conn){

try {

connclose();

conn=null;

} catch (SQLException e) {

eprintStackTrace();

}

}

public static Statement getStmt(Connection conn){

Statement stmt=null;

try {

stmt=conncreateStatement();

} catch (SQLException e) {

eprintStackTrace();

}

return stmt;

}

public static void closeStmt(Statement stmt){

try {

stmtclose();

stmt=null;

} catch (SQLException e) {

eprintStackTrace();

}

}

public static PreparedStatement getpStmt(Connection conn,String sql){

PreparedStatement pStmt=null;

try {

pStmt=connprepareStatement(sql);

} catch (SQLException e) {

eprintStackTrace();

}

return pStmt;

}

public static void closePstmt(Statement pstmt){

try {

pstmtclose();

pstmt=null;

} catch (SQLException e) {

eprintStackTrace();

}

}

public static ResultSet getRs(Statement stmt,String sql){

ResultSet rs=null;

try {

rs=stmtexecuteQuery(sql);

} catch (SQLException e) {

eprintStackTrace();

}

return rs;

}

public static void closeRs(ResultSet rs){

try {

rsclose();

rs=null;

} catch (SQLException e) {

eprintStackTrace();

}

}

}

以上就是关于急!java web课程设计中,连接数据库用户名和密码验证问题,输入密码跳转不到huanying1.jsp全部的内容,包括:急!java web课程设计中,连接数据库用户名和密码验证问题,输入密码跳转不到huanying1.jsp、求助:java课程设计 图书基本信息管理,越简单越好。、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10163506.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存