欢迎来到天天文库
浏览记录
ID:15389370
大小:48.00 KB
页数:6页
时间:2018-08-03
《java和mysql数据库连接完整的程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、JavaMysql数据库的连接及简单功能的,有功能划分,管理员和游客界面。Test.javapackagejdbcs;importjava.sql.*;classTest{String[]st=newString[200];privateStatementstatement;ResultSetrs;privateinti;privateintrs1;publicTest(Strings1,Strings2)throwsClassNotFoundException,SQLException{Stringdriver="com.mysq
2、l.jdbc.Driver";Stringurl="jdbc:mysql://127.0.0.1:3306/bookstore";Stringuser="root";Stringpassword="123456";inti=0;Class.forName(driver);Connectionconn=DriverManager.getConnection(url,user,password);if(!conn.isClosed())System.out.println("连接数据库成功!");statement=conn.creat
3、eStatement();}//查询publicvoidSelect()throwsSQLException{Stringsql1="select*fromuser";rs=statement.executeQuery(sql1);System.out.println("以下是查询到的数据:");while(rs.next()){//st[i++]=rs.getString("Name")+""+rs.getString("Password");//System.out.println(st[i-1]);System.out.pri
4、ntln(rs.getString("Name")+""+rs.getString("Password"));}}}login.javapackagejdbcs;importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.*;publicclassloginextendsJFrameimplementsActionListener{JTextFieldf1;JTextFieldf2;pu
5、bliclogin(){Containerct=getContentPane();ct.setLayout(newGridLayout(3,2));JLabell1=newJLabel("name");JLabell2=newJLabel("password");f1=newJTextField(15);f2=newJTextField(15);JButtonb1=newJButton("确定");JButtonb2=newJButton("重置");ct.add(newLabel("Name"));ct.add(f1);ct.ad
6、d(newLabel("Password"));ct.add(f2);ct.add(b1);ct.add(b2);b1.addActionListener(newEnter());b2.addActionListener(newReWrite());setTitle("login");setSize(300,120);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}classReWriteimplementsActionListener{publicv
7、oidactionPerformed(ActionEvente){f1.setText("");f2.setText("");f1.requestFocus();}}classEnterimplementsActionListener{publicvoidactionPerformed(ActionEvente){if((f1.getText()).equals("admin")&&(f2.getText()).equals("123")){JOptionPane.showMessageDialog(null,"登陆成功,你的权限是
8、管理员");adminm=newadmin();m.setResizable(false);m.show();m.setTitle("管理员界面");}elseif((f1.getText()).equals("snake")&&(f
此文档下载收益归作者所有