************************照片*********************************
public static int insertPic(String path,String pid)
{//flag=0表示上传成功 1表示找不到文件 2表示文件已经存在
int flag=0;
File f=new File(path);//获取选取的图片文件
try
{
con=getConnection();
psInsert=con.prepareStatement("insert into photo values(?,?,?)");
byte[] b=new byte[(int)f.length()];
FileInputStream fin=new FileInputStream(f);//
fin.read(b);fin.close();
psInsert.setString(1,pid);//设置此照片所属联系人
psInsert.setString(2,f.getName());//设置此照片名称
psInsert.setBytes(3,b);//设置照片数据
psInsert.executeUpdate();psInsert.close();//执行更新并关闭语句
}
catch(FileNotFoundException fnfe){flag=1;}//找不到照片文件
catch(SQLException
sqle){flag=2;}//文件已经存在
catch(Exception e){e.printStackTrace();}
finally{DButil.closeCon();}//关闭数据库连接
return flag;
}
public static void main(String[] args)
{
System.out.println(DButil.delUser("aa"));
}
}
Login.java
package tongxunlu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Login extends JFrame implements ActionListener
{
private JPanel jp=new JPanel();
private JLabel[] jlArray={new JLabel("用户名"),new JLabel("密 码"),new JLabel(""),};
private JButton[] jbArray={new JButton("登录"),new JButton("注册"),
new JButton("修改密码"),new JButton("删除用户")};
private JTextField jtf=new JTextField();
private JPasswordField jpf=new JPasswordField();
public Login()
{
jp.setLayout(null);
for(int i=0;i<2;i++)
{
jlArray[i].setBounds(30,20+i*50,80,26);
jbArray[i].setBounds(50+i*110,120,90,26);
jp.add(jlArray[i]);
jp.add(jbArray[i]);
jbArray[i].addActionListener(this);
}
//添加删除用户和修改密码的按钮
for(int i=0;i<2;i++)
{
jbArray[i+2].setBounds(50+i*110,160,90,26);
jp.add(jbArray[i+2]);
jbArray[i+2].addActionListener(this);
}
jtf.setBounds(80,20,180,30);
jp.add(jtf);
jtf.addActionListener(this);
jpf.setBounds(80,70,180,30);
jp.add(jpf);
jpf.setEchoChar('*');
jpf.addActionListener(this);
jlArray[2].setBounds(10,180,300,30);
jp.add(jlArray[2]);
//设置窗体的图标
Image icon=Toolkit.getDefaultToolkit().getImage("img/ico.gif");
this.setIconImage(icon);
this.add(jp);
this.setTitle("登陆");
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setBounds(100,100,300,250);
this.setVisible(true);
}
public void clear()
{//清空输入框的信息;并把输入焦点到用户名框
jtf.setText("");
jpf.setText("");
jtf.requestFocus();
}
@Override//声明此方法为重写方法
public void actionPerformed(ActionEvent e)
{/*实现登陆窗体业务功能的方法*/
String user=jtf.getText().trim();
String pwd=String.valueOf(jpf.getPassword());
String sql="";
if(e.getSource()==jtf)
{
jpf.requestFocus();
}
else if(e.getSource()==jbArray[0]||e.getSource()==jpf)
{//判断用户名和密码是否匹配
查询数据库
if(DButil.check(user,pwd))
{//
登陆成功
MainFrame mf=new MainFrame(jtf.getText());
this.dispose();
}
else
{//登陆失败
jlArray[2].setText