用数据库制作通讯录示例

工具:sqlite3.8.6

PC机:ubuntu13.10

本示例是利用数据库制作一个简单的通讯录,功能有:查看通讯录,增加联系人,删除联系人,修改联系人,查找联系人。数据库表名为contact。

/*************************************************************************
	> File Name: contact.c
	> Author: kid
	> Mail: 280197326@qq.com 
	> Created Time: 2014年02月25日 星期二 14时30分07秒
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"

sqlite3 *db = NULL;

static int callback(void *NotUsed, int argc, char **argv, char **name)   //回调函数,打印数据库内容
{ 
	int i;
	for(i=0; i<argc; i++){   
		printf("%s = %s\n", name[i], argv[i] ? argv[i] :
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
package main; import java.awt.Color; import java.awt.Font; import java.awt.Image; import java.awt.Toolkit; 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 addWind implements ActionListener { private JFrame wind; //定义保存用户输入的姓名 private String getname; //定义标签数组 private JLabel[] lbArray={ new JLabel("请输入您要新增的信息内容:"), new JLabel("姓 名:"), new JLabel("性 别:"), new JLabel("出生日期:"), new JLabel("手机号码:"), new JLabel("MSN/QQ:"), new JLabel("现在住址:"), new JLabel("家 乡:"), new JLabel("关 系:"), new JLabel("备 注:")}; //定义文本域数组 private JTextField[] jtfArray={ new JTextField(), new JTextField(30), new JTextField(30), new JTextField(30), new JTextField(30), new JTextField(30), new JTextField(30), new JTextField(30), new JTextField(30), new JTextField(30) }; private JButton btn,btn2; //构造函数 public addWind() { wind = new JFrame("新增通讯信息页面"); wind.setSize(600,600); btn = new JButton("确认添加"); btn2 = new JButton("返回"); wind.setLayout(null); btn.setBounds(220,500,100,30); btn2.setBounds(360,500,100,30); wind.add(btn); wind.add(btn2); addComponent(); addListener(); Image icon = Toolkit.getDefaultToolkit().getImage("./image/test.PNG"); wind.setIconImage(icon); wind.setVisible(true); //wind.setBackground(Color.red); wind.setLocationRelativeTo(null); wind.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { int temp = JOptionPane.showConfirmDialog(wind, "您是要退出系统,还是返回登录?", "请选择退出或者登录?", JOptionPane.WARNING_MESSAGE); if(temp==0) { System.exit(0); }else { wind.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); } } }); } public void addComponent() { lbArray[0].setFont(new Font("楷体",Font.BOLD+Font.ITALIC,22)); lbArray[0].setForeground(Color.red); lbArray[0].setBounds(100,10,800,20); for(int i=1;i<10;i++) { lbArray[i].setBounds(60,i*50,150,30); lbArray[i].setFont(new Font("楷体",Font.BOLD,20)); lbArray[i].setForeground(Color.blue); jtfArray[i].setBounds(210,i*50,300,30); wind.add(jtfArray[i]); } for(int i=0;i<10;i++) { wind.add(lbArray[i]); } } //注册监听器 public void addListener() { btn.addActionListener(this); btn2.addActionListener(this); for(int i=0;i<10;i++) { jtfArray[i].addActionListener(this); } } //实现ActionListener接口 public void actionPerformed(ActionEvent e) { if(e.getSource()==btn) { //点击更新按钮的操作 getname=jtfArray[1].getText().trim(); System.out.println("test:"+getname); if(getname!=null&&!getname.equals("")) { //拼装SQL语句 String sql = "select name from memoData where name='"+getname+"';"; System.out.println("要更新姓名是:"+getname); DBTool.initialConnect(); if( DBTool.checkData(sql,getname,wind)); { //定义正则表达式,验证电话号码有效性 String parten="1[3|5|8]\\d{9}"; String uname=jtfArray[1].getText().trim(); String sex=jtfArray[2].getText().trim(); String birth=jtfArray[3].getText().trim(); String mobile=jtfArray[4].getText().trim(); if(mobile.matches(parten)) { }else { JOptionPane.showMessageDialog(wind, "您输入的电话号码有误,请检查后再试。", "温馨提示:", JOptionPane.WARNING_MESSAGE); return ; } String msn=jtfArray[5].getText().trim(); String address=jtfArray[6].getText().trim(); String home=jtfArray[7].getText().trim(); String extend=jtfArray[8].getText().trim(); String others=jtfArray[9].getText().trim(); //拼装SQL语句 sql="insert into memoData values('"+uname+"', "+ "'"+sex+"',"+"'"+birth+"', "+"'"+ mobile+"' ,"+"'"+msn+"', "+"'"+address+"' ,"+"'" +home+"', "+"'"+extend+"' ,"+"'"+others+"');"; DBTool.initialConnect(); DBTool.insertData(sql,wind); } }else { JOptionPane.showMessageDialog(wind, "姓名不能为空哦。。", "温馨提示:", JOptionPane.WARNING_MESSAGE); } }else if(e.getSource()==btn2) { //点击返回按钮的操作 new MainWind(); wind.dispose(); }else if(e.getSource()==jtfArray[0]) { jtfArray[1].requestFocus(true); }else if(e.getSource()==jtfArray[1]) { jtfArray[2].requestFocus(true); }else if(e.getSource()==jtfArray[2]) { jtfArray[3].requestFocus(true); }else if(e.getSource()==jtfArray[3]) { jtfArray[4].requestFocus(true); }else if(e.getSource()==jtfArray[4]) { jtfArray[5].requestFocus(true); }else if(e.getSource()==jtfArray[5]) { jtfArray[6].requestFocus(true); }else if(e.getSource()==jtfArray[6]) { jtfArray[7].requestFocus(true); }else if(e.getSource()==jtfArray[7]) { jtfArray[8].requestFocus(true); }else if(e.getSource()==jtfArray[8]) { jtfArray[9].requestFocus(true); }else if(e.getSource()==jtfArray[9]) { btn2.requestFocus(true); } } }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值