ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:18.30KB ,
资源ID:9451778      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9451778.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(java通讯录连接mysql数据库.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

java通讯录连接mysql数据库.docx

1、java通讯录连接mysql数据库package jdbc;import java.awt.Container;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.*;public class Denglu extends

2、WindowAdapter implements ActionListener JFrame f=new JFrame(登录); Container c = f.getContentPane(); JLabel I=new JLabel(账号:,JLabel.CENTER); JLabel P=new JLabel(密码:,JLabel.CENTER); JTextField tI=new JTextField(11); JPasswordField tP=new JPasswordField(11); JButton confirm=new JButton(确定); JButton canc

3、el=new JButton(取消); JPanel p1=new JPanel(new FlowLayout(FlowLayout.CENTER,7,3); JPanel p2=new JPanel(new FlowLayout(FlowLayout.CENTER,7,3); JPanel p3=new JPanel(new FlowLayout(FlowLayout.CENTER,7,0); String ID=; String PW=; Object option = new Object查询,新建; public Denglu() tP.setEchoChar(*); c.setLay

4、out(new GridLayout(3,1); p1.add(I); p1.add(tI); p2.add(P); p2.add(tP); p3.add(confirm); p3.add(cancel); f.add(p1); f.add(p2); f.add(p3); f.setBounds(300, 200,70, 50); f.setVisible(true); f.pack(); confirm.addActionListener(this); cancel.addActionListener(this); f.setDefaultCloseOperation(JFrame.EXIT

5、_ON_CLOSE); public static void main(String args) new Denglu(); public void windowClosing(WindowEvent e) System.exit(0); public void actionPerformed(ActionEvent e) if (e.getSource()=confirm) if (ID.equals(tI.getText()&PW.equals(new String(tP.getPassword() f.dispose(); JOptionPane.showMessageDialog(nu

6、ll, 登录成功, 提示,JOptionPane.INFORMATION_MESSAGE); new ChioceDialog(); else JOptionPane.showMessageDialog(null, 用户名或密码错误,请重新登录, 提示,JOptionPane.ERROR_MESSAGE); else if (e.getSource()=cancel) System.exit(1); class ChioceDialog extends WindowAdapter implements ActionListener int newx = 0; New newone = null

7、; Reference reference =null; JDialog jDialog = new JDialog(); JButton referButton = new JButton(查询); JButton newButton = new JButton(新建); String name; public ChioceDialog() Container container = jDialog.getContentPane(); jDialog.setBounds(300,120,240,60); jDialog.setTitle(通讯录); container.setLayout(n

8、ew GridLayout(1,2,20,10); container.add(referButton); container.add(newButton); jDialog.setVisible(true); jDialog.validate(); newButton.addActionListener(this); referButton.addActionListener(this); jDialog.addWindowListener(this); public void windowClosing (WindowEvent e) if (newx = 1) reference.clo

9、se(); else if (newx = 2) newone.close(); System.exit(1); public void actionPerformed(ActionEvent d) if (d.getSource()=referButton) try reference = new Reference(); newx = 1; catch (Exception e) / TODO Auto-generated catch block e.printStackTrace(); else if(d.getSource()=newButton) try newone = new N

10、ew(); newx = 2; catch (Exception e) / TODO Auto-generated catch block e.printStackTrace(); package jdbc;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.sql.Connection;import jav

11、a.sql.DatabaseMetaData;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class AddressBook extends WindowAdapter implements ActionListener Statement st = null; Connection conn; ResultSet rsTables; ResultSet rs; Frame f=new Frame(通讯录); Label title=new Label(个人基本

12、信息表,Label.CENTER); Label qqLabel=new Label( QQ: ,Label.CENTER); Label nameLabel=new Label(姓名:,Label.CENTER); Label sexLabel=new Label(性别:,Label.CENTER); Label telLabel=new Label( Tel: ,Label.CENTER); Label emaiLabel=new Label(Email:,Label.CENTER); Label hobbyLabel=new Label(兴趣:,Label.CENTER); Label

13、addtext = new Label(备注); TextField nameTextField=new TextField(17); TextField qqTextField=new TextField(17); TextField telTextField=new TextField(17); TextField emailTextField=new TextField(17); TextArea text = new TextArea(4,3); Button confirm=new Button(确定); Button submit =new Button(重置); Button k

14、nowButton=new Button(确定); Panel p1 = new Panel(new FlowLayout(FlowLayout.CENTER,10,3); Panel p7 = new Panel(new FlowLayout(FlowLayout.CENTER,10,3); Panel p8 = new Panel(new GridLayout(2,1); Panel p3 = new Panel(new BorderLayout(3,3); Panel p2 = new Panel(new FlowLayout(FlowLayout.CENTER,66,1); Panel

15、 p4 = new Panel(new BorderLayout(); Panel p5 = new Panel(new FlowLayout(FlowLayout.LEFT,15,1); Panel p6 = new Panel(new FlowLayout(FlowLayout.RIGHT,10,1); static CheckboxGroup csex = new CheckboxGroup(); static Checkbox male =new Checkbox(男, true, csex); static Checkbox female =new Checkbox(女,false,

16、 csex); static Checkbox read=new Checkbox(阅读,false); static Checkbox basketball=new Checkbox(篮球); static Checkbox run=new Checkbox(跑步); static String result; static String result2; public void close() System.exit(0); public AddressBook() throws Exception Class.forName(com.mysql.jdbc.Driver); /2建立连接

17、String url = jdbc:mysql:/localhost:3306/test; String user = root; String password = 1993; conn = DriverManager.getConnection(url, user, password); DatabaseMetaData meta = conn.getMetaData(); rsTables = meta.getTables(null , null, AddressBook, null); st = conn.createStatement(); void gui() p1.add(nam

18、eLabel); p1.add(nameTextField); p1.add(qqLabel); p1.add(qqTextField); p7.add(telLabel); p7.add(telTextField); p7.add(emaiLabel); p7.add(emailTextField); p8.add(p1); p8.add(p7); f.setBounds(300, 200,0, 0); f.add(title,North); p4.add(p8,North); p5.add(sexLabel); p5.add(male); p5.add(female); p6.add(ho

19、bbyLabel); p6.add(read); p6.add(basketball); p6.add(run); p4.add(p5); p4.add(p6,East); p4.add(p3,South); f.add(p4); p3.add(addtext,West); p3.add(text); f.add(p2,South); f.addWindowListener(this); public static String checkString() if (male.getState() result=male.getLabel(); else result=female.getLab

20、el(); return result; public static String checkString2() if (read.getState() result2=read.getLabel(); if (basketball.getState() result2+= +basketball.getLabel(); if (run.getState() result2+= +run.getLabel(); return result2; public void windowClosing(WindowEvent e) f.dispose(); Override public void a

21、ctionPerformed(ActionEvent arg0) / TODO Auto-generated method stub package jdbc;import java.awt.Color;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.sql.SQLException;import javax.swing.JOptionPane;public class New extends AddressBook public New() throws Exception super(); gu

22、i(); p2.add(confirm); p2.add(submit); confirm.setPreferredSize(new Dimension(70,25); submit.setPreferredSize(new Dimension(70,25); confirm.setBackground(Color.cyan); submit.setBackground(Color.cyan); confirm.addActionListener(this); submit.addActionListener(this); f.setVisible(true); f.pack(); publi

23、c void actionPerformed(ActionEvent e) if(e.getSource()=confirm) if (nameTextField.getText().equals() JOptionPane.showMessageDialog(null, 姓名不能为空); else String str = CREATE TABLE AddressBook(name VARCHAR(20),qq VARCHAR(17), + tel VARCHAR(20),email VARCHAR(30),sex CHAR(2),hobby VARCHAR(14),addtext TEXT

24、); String s1 = +nameTextField.getText()+,+qqTextField.getText()+; String s2=+telTextField.getText()+,+emailTextField.getText()+,+AddressBook.checkString()+; String s3=+AddressBook.checkString2()+,+text.getText()+; String tem = insert into addressbook values(+s1+,+s2+,+s3+); try st.executeUpdate(str)

25、; st.executeUpdate(tem); st.close(); conn.close(); f.dispose(); JOptionPane.showMessageDialog(null, 添加成功!); catch (SQLException e1) e1.printStackTrace(); if(e.getSource() = submit) nameTextField.setText(); qqTextField.setText(); telTextField.setText(); emailTextField.setText(); male.setState(true);

26、read.setState(false); basketball.setState(false); run.setState(false); text.setText(); package jdbc;import java.awt.Color;import java.awt.Dimension;import java.awt.event.ActionEvent;import javax.swing.JOptionPane;import java.sql.ResultSet;import java.sql.SQLException;public class Reference extends A

27、ddressBook String name; int num=0; public Reference() throws Exception super(); if(rsTables.next() = false) JOptionPane.showMessageDialog(null, 无数据,请添加); else do name =JOptionPane.showInputDialog(null,请输入你要查询的姓名:,查询,JOptionPane.INFORMATION_MESSAGE); if (name.equals() JOptionPane.showMessageDialog(null,请输入姓名!,null,JOptionPane.WARNING_MESSAGE); while(name.equals(); if (name !=null)

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1