概述
链接:https://pan.baidu.com/s/1UFfqy_mN2tnz8Q4Fclmwqw
提取码:yrk1
复制这段内容后打开百度网盘手机App,操作更方便哦
package bean;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import zsgc.cha;
public class HashMapTest4
{
public static void main(String[] args)
{
//String [][] tableVales={}; //数据
cha h1 = new cha();
HashMap<String ,String> map = h1.chaxun();
int a= map.size();
String [][] tableVales = new String[a][a];
String [] xxx= new String[a];
int xx=0;
String [] yyy = new String[a];
int yy=0;
Set set = map.entrySet();
for(Iterator iter = set.iterator(); iter.hasNext();)
{
Map.Entry entry = (Map.Entry)iter.next();
String key = (String)entry.getKey();
String value = (String)entry.getValue();
xxx[xx] = key;
yyy[yy] = value;
++xx;
++yy;
System.out.println(key +" " + value);
}
for(int i=0;i<a;i++)
{
tableVales[i][0]=xxx[i];
System.out.println("hahaha"+xxx[i]);
}
for(int y=0;y<a;y++)
{
tableVales[y][1]= yyy[y];
System.out.println("xixixi" + yyy[y]);
}
for(int z=0;z<a;z++)
{
for(int c=0;c<2;c++)
{
System.out.println("jiahnag"+tableVales[z][c]);
}
System.out.println("n");
}
}
}
package bean;
public class user {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class mysql {
public boolean lianjie (String a, String b)
{
boolean aa= false;
int bb = 0;
Connection con = null;
Statement stmt;
ResultSet rs;
final String URL= "jdbc:mysql://localhost:3306/java?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
final String NAME="root";//登录名
final String PASSWORD="123456";//密码
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("未能成功加载驱动程序,请检查是否导入驱动程序!");
//添加一个println,如果加载驱动异常,检查是否添加驱动,或者添加驱动字符串是否错误
e.printStackTrace();
}
try {
con = DriverManager.getConnection(URL, NAME, PASSWORD);
System.out.println("获取数据库连接成功!");
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
//添加一个println,如果连接失败,检查连接字符串或者登录名以及密码是否错误
e.printStackTrace();
}
//数据库打开后就要关闭
if(con!=null)
{
try {
stmt = con.createStatement();
rs = stmt.executeQuery("select name,password from user");
while (rs.next()) {
String name = rs.getString(1);
String password = rs.getString(2);
//System.out.println("666");
//System.out.println(a);
//System.out.println(b);
//System.out.println(name);
//System.out.println(password);
if(name.equals(a))
{
if(password.equals (b))
{
bb=1;
}
System.out.println("666");
//bb = 1;
//return aa;
}
}
// 释放相关的资源
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
con=null;
}
}
if(bb==1)
{
aa=true;
}
return aa;
}
}
package dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class mysql1 {
public boolean chaxun(String a, String b)
{
Connection con = null;
Statement stmt;
ResultSet rs;
final String URL= "jdbc:mysql://localhost:3306/java?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
final String NAME="root";//登录名
final String PASSWORD="123456";//密码
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("未能成功加载驱动程序,请检查是否导入驱动程序!");
//添加一个println,如果加载驱动异常,检查是否添加驱动,或者添加驱动字符串是否错误
e.printStackTrace();
}
try {
con = DriverManager.getConnection(URL, NAME, PASSWORD);
System.out.println("获取数据库连接成功!");
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
//添加一个println,如果连接失败,检查连接字符串或者登录名以及密码是否错误
e.printStackTrace();
}
//数据库打开后就要关闭
if(con!=null)
{
try {
stmt = con.createStatement();
String name = a;
String password =b;
stmt.executeUpdate("insert into user(name, password )"
+ "VALUE( '" +name+ "' , '" + password + "')"); //变量插入数据
// 释放相关的资源
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
con=null;
}
}
return true;
}
}
package loge;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import dao.mysql;
import yemian.yemian;
//LoginFrame 登陆窗口 功能 实现用户登陆 ,如果成功就跳转
//LoginFrame 继承于窗口类, 并实现ActionListener接口
public class LoginFrame extends JFrame implements ActionListener {
// 申明需要的组件
JButton jb1, jb2,jb3;//按钮
JTextField jtf1;//文本框
JPasswordField jpf1;//密码框
JTextField jtf2;
public LoginFrame() {
// 窗口属性的设置
setTitle("贾航制作");// 窗口标题
setSize(500, 300);// 窗口大小
setLocationRelativeTo(null);// 窗口居中
setDefaultCloseOperation(EXIT_ON_CLOSE);// 关闭窗口则退出虚拟机
setLayout(new FlowLayout());// 设置布局流式布局
JPanel jp = new JPanel(new GridLayout(6, 1));// 设置面板为表格布局4行1列
// 第一行
JPanel jp1 = new JPanel();
JLabel jl1 = new JLabel("账号 ");
jtf1 = new JTextField(12);
jp1.add(jl1);
jp1.add(jtf1);
jp.add(jp1);
// 第二行
JPanel jp2 = new JPanel();
JLabel jl2 = new JLabel("密码 ");
jpf1 = new JPasswordField(12);
jp2.add(jl2);
jp2.add(jpf1);
jp.add(jp2);
// 第三行
JPanel jp5 = new JPanel();
JLabel jl5 = new JLabel("验证码 ");
jtf2 = new JTextField(12);
jp5.add(jl5);
jp5.add(jtf2);
jp.add(jp5);
//第四行
yanzhengma panel = new yanzhengma();
jp.add(panel);
// 第五行
JPanel jp3 = new JPanel();
jb1 = new JButton("登陆");
jb1.addActionListener(this);// 添加动作响应器
jb2 = new JButton("重置");
jb2.addActionListener(this);// 添加动作响应器
jp3.add(jb1);
jp3.add(jb2);
jp.add(jp3);
// 第六行
JPanel jp4 = new JPanel();
jb3 = new JButton("欢迎新用户注册");
jb3.addActionListener(this);
jp4.add(jb3);
jp.add(jp4);
add(jp);
}
// 动作响应
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();// 根据动作命令,来进行分别处理
if (cmd.equals("登陆")) {
String id = jtf1.getText();// 取得用户名
String key = new String(jpf1.getPassword());// 取得密码
mysql h1 = new mysql();
if (h1.lianjie(id, key)) {// 判断是否登录成功
// 如果登录成功
setVisible(false);// 本窗口隐藏,
yemian jTableDefaultTableModelTest = new yemian();
jTableDefaultTableModelTest.setVisible(true);
// new MainFrame(id).setVisible(true);// 新窗口显示
dispose();//本窗口销毁,释放内存资源
} else {
//如果登录失败 弹出提示
JOptionPane.showMessageDialog(this, "用户名或者密码错误.", "通知", JOptionPane.ERROR_MESSAGE);
clearText();//清空文本框 密码框的输入
}
} else if (cmd.equals("重置")) {
clearText();
}
else if(cmd.equals("欢迎新用户注册")) {
new zhuce().setVisible(true);// 新窗口显示
dispose();//本窗口销毁,释放内存资源
}
}
private void clearText() {//清空文本框, 密码框的输入
jtf1.setText("");
jpf1.setText("");
jtf2.setText("");
}
//main方法, 程序的入口
public static void main(String[] args) {
new LoginFrame().setVisible(true);//创建登录窗口,并可见
}
}
package loge;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MainFrame extends JFrame {
public MainFrame(String name) {
setTitle("学生信息管理系统");//标题
setSize(600, 600);//大小
setLocationRelativeTo(null);//居中
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp = new JPanel();
JLabel jl1 = new JLabel("欢迎");
JLabel jl2 = new JLabel(name);
jl2.setForeground(Color.BLUE);//设置文本颜色
JLabel jl3 = new JLabel("使用系统.");
jp.add(jl1);
jp.add(jl2);
jp.add(jl3);
add(jp, BorderLayout.NORTH);
JTextArea jta = new JTextArea();
jta.setLineWrap(true);
jta.append("消息提示");
jta.append(" 消息!通知~!");
JScrollPane jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(jsp);
JPanel jp2 = new JPanel();
JButton jb = new JButton("退出");
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);//退出
}
});
jp2.add(jb);
add(jp2,BorderLayout.SOUTH);
}
}
package loge;
import java.awt.*;
import java.util.Random;
import java.awt.event.*;
public class yanzhengma extends Panel {
public void paint(Graphics g)
{
int width=160;
int height=40;
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, width, height);
g.setColor(Color.BLACK);
g.drawRect(0, 0, width-1, height-1);
Random r = new Random();
for(int i=0;i<100;i++)
{
int x=r.nextInt(width) - 2;
int y=r.nextInt(height) - 2;
g.drawOval(x, y, 2, 2);
}
g.setFont(new Font("黑体",Font.BOLD,30));
g.getColor();
char[] chars=("0123456789abcdefghijkmnopqrstvuwxyzABCDEFG"+"HIJKLMNOPQRSTVUWSYZ").toCharArray();
StringBuilder sb =new StringBuilder();
for(int i=0;i<4;i++)
{
int pos=r.nextInt(chars.length);
char c= chars[pos];
sb.append(c+"");
}
g.drawString(sb.toString(),20 , 30);
}
}
package loge;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import dao.mysql;
import dao.mysql1;
public class zhuce extends JFrame {
public zhuce() {
JButton jb1, jb2;
JTextField jtf1,jtf2;
setTitle("注册窗口");// 窗口标题
setSize(500, 300);// 窗口大小
setLocationRelativeTo(null);// 窗口居中
setDefaultCloseOperation(EXIT_ON_CLOSE);// 关闭窗口则退出虚拟机
setLayout(new FlowLayout());// 设置布局流式布局
JPanel jp = new JPanel(new GridLayout(3, 1));// 设置面板为表格布局4行1列
// 第一行
JPanel jp1 = new JPanel();
JLabel jl1 = new JLabel("账号 ");
jtf1 = new JTextField(12);
jp1.add(jl1);
jp1.add(jtf1);
jp.add(jp1);
// 第二行
JPanel jp2 = new JPanel();
JLabel jl2 = new JLabel("密码 ");
jtf2 = new JPasswordField(12);
jp2.add(jl2);
jp2.add(jtf2);
jp.add(jp2);
// 第三行
JPanel jp3 = new JPanel();
jb1 = new JButton("注册");
// jb1.addActionListener(this);// 添加动作响应器
jb2 = new JButton("重置");
// jb2.addActionListener(this);// 添加动作响应器
jp3.add(jb1);
jp3.add(jb2);
jp.add(jp3);
add(jp);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String id = jtf1.getText();// 取得用户名
String key = jtf2.getText();//
System.out.println(id);
System.out.println(key);
mysql1 h = new mysql1();
String aaaa="";
String bbbb="";
if(id.equals(aaaa)&&key.equals(bbbb)) {
JOptionPane.showMessageDialog(null, "贾航告诉你账号或者密码不能为空.", "贾航给你的警告",JOptionPane.PLAIN_MESSAGE);
}
else
{
h.chaxun(id, key);
JOptionPane.showMessageDialog(null, "恭喜你注册成功", "贾航给你的温馨提示",JOptionPane.PLAIN_MESSAGE);
jtf1.setText("");
jtf2.setText("");
//System.out.println("注册成功");
}
// String key = new String(jpf1.getPassword());// 取得密码
// System.exit(0);//退出
}
});
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jtf1.setText("");
jtf2.setText("");
}
});
}
}
package yemian;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import zsgc.cha;
import zsgc.gai;
import zsgc.shan;
import zsgc.zeng;
//维护表格
public class yemian extends JFrame{
private DefaultTableModel tableModel; //表格模型对象
private JTable table;
private JTextField aTextField;
private JTextField bTextField;
public yemian()
{
super();
//DefaultTableModel tableModel; //表格模型对象
// JTable table;
// JTextField aTextField ;
// JTextField bTextField;
setTitle("密码管理系统");
setBounds(100,100,500,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String[] columnNames = {"用户名","密码"}; //列名
cha h4 = new cha();
HashMap<String ,String> map = h4.chaxun();
int a= map.size();
System.out.println("Map集合大小为:"+map.size());
//String [][] tableVales={}; //数据
// String [][]tableVales={{"123","123"},{"456","456"},{"789","789"},{"000","000"},{"111","111"}};
String [][] tableVales = new String[a][a];
String [] xxx= new String[a];
int xx=0;
String [] yyy = new String[a];
int yy=0;
Set set = map.entrySet();
for(Iterator iter = set.iterator(); iter.hasNext();)
{
Map.Entry entry = (Map.Entry)iter.next();
String key = (String)entry.getKey();
String value = (String)entry.getValue();
xxx[xx] = key;
yyy[yy] = value;
++xx;
++yy;
System.out.println(key +" " + value);
}
for(int i=0;i<a;i++)
{
tableVales[i][0] = xxx[i];
System.out.println("hahaha"+xxx[i]);
}
for(int y=0;y<a;y++)
{
tableVales[y][1]= yyy[y];
System.out.println("xixixi" + yyy[y]);
}
for(int z=0;z<a;z++)
{
for(int c=0;c<2;c++)
{
System.out.println("jiahnag"+tableVales[z][c]);
}
System.out.println("n");
}
tableModel = new DefaultTableModel(tableVales,columnNames);
table = new JTable(tableModel);
JScrollPane scrollPane = new JScrollPane(table); //支持滚动
getContentPane().add(scrollPane,BorderLayout.CENTER);
//jdk1.6
//排序:
//table.setRowSorter(new TableRowSorter(tableModel));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //单选
table.addMouseListener(new MouseAdapter(){
//鼠标事件
public void mouseClicked(MouseEvent e){
int selectedRow = table.getSelectedRow(); //获得选中行索引
Object oa = tableModel.getValueAt(selectedRow, 0);
Object ob = tableModel.getValueAt(selectedRow, 1);
aTextField.setText(oa.toString()); //给文本框赋值
bTextField.setText(ob.toString());
}
});
scrollPane.setViewportView(table);
final JPanel panel = new JPanel();
getContentPane().add(panel,BorderLayout.SOUTH);
panel.add(new JLabel("A: "));
aTextField = new JTextField("A4",10);
panel.add(aTextField);
panel.add(new JLabel("B: "));
bTextField = new JTextField("B4",10);
panel.add(bTextField);
final JButton addButton = new JButton("添加"); //添加按钮
addButton.addActionListener(new ActionListener(){//添加事件
public void actionPerformed(ActionEvent e){
String []rowValues = {aTextField.getText(),bTextField.getText()};
// Object a = tableModel.getValueAt(rowCount+1, 0);
//Object b = tableModel.getValueAt(rowCount+1, 1);
String a = rowValues[0];
String b = rowValues[1];
System.out.println(a);
System.out.println(b);
zeng h2 = new zeng();
if( h2.zengtian(a, b))
{
System.out.println("数据库中添加成功");
}
tableModel.addRow(rowValues); //添加一行
int rowCount = table.getRowCount() +1; //行数加上1
aTextField.setText("A"+rowCount);
bTextField.setText("B"+rowCount);
}
});
panel.add(addButton);
final JButton updateButton = new JButton("修改"); //修改按钮
updateButton.addActionListener(new ActionListener(){//添加事件
public void actionPerformed(ActionEvent e){
int selectedRow = table.getSelectedRow();//获得选中行的索引
Object a = tableModel.getValueAt(selectedRow, 0);
String aaa = (String) a;
if(selectedRow!= -1) //是否存在选中行
{
//修改指定的值:
tableModel.setValueAt(aTextField.getText(), selectedRow, 0);
tableModel.setValueAt(bTextField.getText(), selectedRow, 1);
//table.setValueAt(arg0, arg1, arg2)
}
Object b = tableModel.getValueAt(selectedRow, 0);
String bbb = (String) b;
Object c = tableModel.getValueAt(selectedRow, 1);
String ccc = (String) c;
System.out.println("aaa="+aaa+"bbb="+bbb+"ccc"+ccc);
gai h3 = new gai();
if(h3.xiugai(bbb, ccc, aaa))
{
System.out.println("数据库中修改成功");
}
}
});
Component add = panel.add(updateButton);
final JButton delButton = new JButton("删除");
delButton.addActionListener(new ActionListener(){//添加事件
public void actionPerformed(ActionEvent e){
int selectedRow = table.getSelectedRow();//获得选中行的索引
if(selectedRow!=-1) //存在选中行
{
Object a = tableModel.getValueAt(selectedRow, 0);
shan h1 = new shan();
if( h1.shanchu((String)a))
{
System.out.println("数据库中删除成功");
}
System.out.println(a);
tableModel.removeRow(selectedRow); //删除行
}
}
});
panel.add(delButton);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
yemian jTableDefaultTableModelTest = new yemian();
jTableDefaultTableModelTest.setVisible(true);
}
}
package zsgc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
public class cha {
public HashMap<String, String> chaxun()
{
Connection con = null;
Statement stmt;
ResultSet rs;
// TODO 自动生成的方法存根
//serverTimezone=GMT
//final String URL="jdbc:mysql://localhost:3306/jiahang?useUnicode=true&characterEncoding=utf8&GMT%2B8&useSSL=false";
// final String URL="jdbc:mysql://localhost:3306/jiahang?useSSL=false";//数据库连接字符串,这里的imylove为数据库名
final String URL= "jdbc:mysql://localhost:3306/java?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
final String NAME="root";//登录名
final String PASSWORD="123456";//密码
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("未能成功加载驱动程序,请检查是否导入驱动程序!");
//添加一个println,如果加载驱动异常,检查是否添加驱动,或者添加驱动字符串是否错误
e.printStackTrace();
}
try {
con = DriverManager.getConnection(URL, NAME, PASSWORD);
System.out.println("获取数据库连接成功!");
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
//添加一个println,如果连接失败,检查连接字符串或者登录名以及密码是否错误
e.printStackTrace();
}
//数据库打开后就要关闭
if(con!=null)
{
try {
stmt = con.createStatement();
//String = new String("11");
//String address1 = new String("11");
//int id = 20;
// String aa = "11";
//int password = 112233;
//stmt.executeUpdate("insert into users(id,name, password )"
// + "VALUE(' " + id +"' , '" +name+ "' , '" + password + "')"); //变量插入数据
//stmt.executeUpdate("insert into users values ('333','333','333')"); //增添数据
// stmt.executeUpdate("delete from users where id = 20 "); //删除数据
// stmt.executeUpdate("delete from users "); //删除所有的数据
//stmt.executeUpdate("update users set id = 666 where id = 333 "); //修改数据
//stmt.executeUpdate("update users set id = 888 , name = 'jiahang' where password = 333 "); //修改字符串数据
//stmt.execute("create table userrr (id int ,name varchar(20),password int );"); //创建一个表
//stmt.execute("drop table userr; "); //删除一个表
//stmt.executeUpdate("CREATE DATABASE jiahangjia;"); //创建一个数据库
// stmt.execute("drop database jiahang"); //删除一个数据库
rs = stmt.executeQuery("select name, password from user ");
HashMap<String , String > map = new HashMap<String ,String>();
while (rs.next()) {
//int idd = rs.getInt(1);
String namee = rs.getString(1);
String passwordd = rs.getString(2);
//map.put("a","aa");
map.put(namee,passwordd);
// 打印数据
// System.out.println("name=" + namee+",password="
// + passwordd);
}
//return map;
// 释放相关的资源
con.close();
return map;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
con=null;
}
}
//return map;
return null;
}
}
package zsgc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class gai {
public boolean xiugai(String a , String b , String c)
{
Connection con = null;
Statement stmt;
ResultSet rs;
final String URL= "jdbc:mysql://localhost:3306/java?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
final String NAME="root";//登录名
final String PASSWORD="123456";//密码
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("未能成功加载驱动程序,请检查是否导入驱动程序!");
//添加一个println,如果加载驱动异常,检查是否添加驱动,或者添加驱动字符串是否错误
e.printStackTrace();
}
try {
con = DriverManager.getConnection(URL, NAME, PASSWORD);
System.out.println("获取数据库连接成功!");
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
//添加一个println,如果连接失败,检查连接字符串或者登录名以及密码是否错误
e.printStackTrace();
}
//数据库打开后就要关闭
if(con!=null)
{
try {
stmt = con.createStatement();
String name = a;
String password = b;
String oldname = c;
stmt.executeUpdate("delete from user where name = " + oldname );
stmt.executeUpdate("insert into user(name, password )"
+ "VALUE( '" +name+ "' , '" + password + "')"); //变量插入数据
// 释放相关的资源
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
con=null;
}
}
return true;
}
}
package zsgc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class shan {
public boolean shanchu(String name) {
Connection con = null;
Statement stmt;
ResultSet rs;
final String URL= "jdbc:mysql://localhost:3306/java?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
final String NAME="root";//登录名
final String PASSWORD="123456";//密码
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("未能成功加载驱动程序,请检查是否导入驱动程序!");
//添加一个println,如果加载驱动异常,检查是否添加驱动,或者添加驱动字符串是否错误
e.printStackTrace();
}
try {
con = DriverManager.getConnection(URL, NAME, PASSWORD);
System.out.println("获取数据库连接成功!");
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
//添加一个println,如果连接失败,检查连接字符串或者登录名以及密码是否错误
e.printStackTrace();
}
//数据库打开后就要关闭
if(con!=null)
{
try {
stmt = con.createStatement();
//String name = a;
String id = name;
//stmt.executeUpdate("insert into user(name, password )"
// + "VALUE( '" +name+ "' , '" + password + "')"); //变量插入数据
stmt.executeUpdate("delete from user where name = " + id );
// 释放相关的资源
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
con=null;
}
}
return true;
}
}
package zsgc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class zeng {
public boolean zengtian(String a, String b)
{
Connection con = null;
Statement stmt;
ResultSet rs;
final String URL= "jdbc:mysql://localhost:3306/java?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
final String NAME="root";//登录名
final String PASSWORD="123456";//密码
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("未能成功加载驱动程序,请检查是否导入驱动程序!");
//添加一个println,如果加载驱动异常,检查是否添加驱动,或者添加驱动字符串是否错误
e.printStackTrace();
}
try {
con = DriverManager.getConnection(URL, NAME, PASSWORD);
System.out.println("获取数据库连接成功!");
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
//添加一个println,如果连接失败,检查连接字符串或者登录名以及密码是否错误
e.printStackTrace();
}
//数据库打开后就要关闭
if(con!=null)
{
try {
stmt = con.createStatement();
String name = a;
String password = b ;
stmt.executeUpdate("insert into user(name, password )"
+ "VALUE( '" +name+ "' , '" + password + "')"); //变量插入数据
//stmt.executeUpdate("delete from user where name = " + id );
// 释放相关的资源
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
con=null;
}
}
return true;
}
}
最后
以上就是小巧月光为你收集整理的密码管理系统的全部内容,希望文章能够帮你解决密码管理系统所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复