java程序相关

来源:百度知道 编辑:UC知道 时间:2024/06/06 11:11:56
public void init_jFrame(){
ctp.add(l_user);
ctp.add(l_pasw);
ctp.add(t_username);
ctp.add(t_password);

ctp.add(b_ok);
ctp.add(b_no);

this.setBounds(300,200,400,300);
this.setResizable(false);//使窗口可以最小化和关闭,但是不能被任意改变大小
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//同时关闭后台运行

}
public void actionPerformed(ActionEvent e) {

// TODO: Add your code here
String name=null,pasw=null,rsname=null,rspasw=null,sql=null;
PreparedStatement pstmt=null;
Connection con=null;
ResultSet rs=null;
if(e.getSource().equals(b_ok)){
name=t_username.getText().trim();
pasw=t_password.getText().trim();
try{
con=JDBC_Connection.getCon();
sql="select * from T_BOOKS_USER ";
pstmt=con.prepareStatement(sql);
//pstmt.setString(1,name);
rs=

哥们你弄得咋那么难啊,嗨,有那么好的 数据库你应该直接用数据库来实现。看我的,
{String sq="select * from 用户 where name='"+user.getText()+"' and mima='"+pas+"'";
try {
String sss=(new DBconnection()).getnumber(sq);
if(sss.equals("null"))
JOptionPane.showMessageDialog(null,"用户名不正确或密码错误!");
else
{
f.setVisible(false);
new Selctapart(f);}
这是其中一段代码。new DBconnection()).getnumber(sq)
这是一个方法
String getnumber(String str) throws ClassNotFoundException, SQLException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection
("jdbc:odbc:"+Source,"","");
st=con.createStatement();
rs=st.executeQuery(str);
rs.next();
int bo=rs.getRow();
String s="";
if(bo!=0)
s=rs.getString(1);
else s="null";
rs.close();