📄 userbean.java
字号:
package com;
import java.sql.*;
public class userbean
{
static String name;
static String password;
static String code="wandou";
static String sex;
static String birthday;
static String duty;
static String workplace;
static String telephone;
static String address;
static String email;
public static Connection con;
public static Statement stmt;
ResultSet rs;
public void getRecord()throws SQLException
{
//加载驱动程序
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(e);
System.exit(-1);
}
con=DriverManager.getConnection("jdbc:odbc:usery","sa","sa");
stmt=con.createStatement();
}
//设置属性值,获取属性值的方法。
public void setCon(Connection conn)
{
con=conn;
}
public Connection getCon()
{
return con;
}
public void setStmt(Statement st)
{
stmt=st;
}
public Statement getStmt()
{
return stmt;
}
public void setName(String n)
{
name=n;
}
public String getName()
{
return name;
}
public void setPassword(String p)
{
password=p;
}
public String getPassword()
{
return password;
}
public void setCode(String c)
{
code=c;
}
public String getCode()
{
return code;
}
public void setSex(String s)
{
sex=s;
}
public String getSex()
{
return sex;
}
public void setBirthday(String b)
{
birthday=b;
}
public String getBirthday()
{
return birthday;
}
public void setDuty(String d)
{
duty=d;
}
public String getDuty()
{
return duty;
}
public void setWorkplace(String w)
{
workplace=w;
}
public String getWorkplace()
{
return workplace;
}
public void setTelephone(String t)
{
telephone=t;
}
public String getTelephone()
{
return telephone;
}
public void setAddress(String a)
{
address=a;
}
public String getAddress()
{
return address;
}
public void setEmail(String e)
{
email=e;
}
public String getEmail()
{
return email;
}
//添加记录到数据库的user表中
public void insert()throws SQLException
{
getRecord();
stmt=con.createStatement();
String s="'"+name+"','"+password+"','"+code+"','"+sex+"','"+birthday+"','"+
duty+"','"+workplace+"','"+telephone+"','"+address+"','"+email+"'";
String cr="insert into qqq values("+s+")";
stmt.executeUpdate(cr);
stmt.close();
con.close();
}
public void update()throws SQLException
{
getRecord();
stmt=con.createStatement();
String dd="update qqq set name='"+name+"',password='"+password+"',sex='"+
sex+"',birthday='"+birthday+"',Duty='"+duty+"',workplace='"+workplace+"',telephone='"
+telephone+"',Address='"+address+"',Email='"+email+"'where code='"+code+"'";
stmt.executeUpdate(dd);
}
public void select()throws SQLException
{
getRecord();
String sql1="select * from qqq where code='"+code+"'";
rs=stmt.executeQuery(sql1);
while(rs.next())
{
name=rs.getString("name");
sex=rs.getString("sex");
duty=rs.getString("Duty");
workplace=rs.getString("workplace");
telephone=rs.getString("Telephone");
address=rs.getString("Address");
email=rs.getString("Email");
}
rs.close();
stmt.close();
con.close();
}
public void delete()throws SQLException
{
getRecord();
String sql2="delete meetingperson where code='"+code+"'";
stmt=con.createStatement();
stmt.executeUpdate(sql2);
stmt.close();
con.close();
}
/* public static void main(String args[])throws SQLException
{
userbean u=new userbean();
u.select();
System.out.println(name);
System.out.println(sex);
System.out.println(duty);
System.out.println(workplace);
System.out.println(telephone);
System.out.println(address);
System.out.println(email);
} */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -