20 个解决方案
#1
肯定是乱码了吧,看看编码是否统一
#2
看看你数据库属性 字符集 应该用utf8 -- UTF-8 Unicode
#3
编码方式不同意,mysql默认的编码是lan1
修改文件my.ini
C:\Program Files\MySQL\MySQL Server 5.1\my.ini
[client]和[mysqld]下面进行修改: default-character-set = utf8
然后重启数据库,再把3条记录删除,重新插入。
修改文件my.ini
C:\Program Files\MySQL\MySQL Server 5.1\my.ini
[client]和[mysqld]下面进行修改: default-character-set = utf8
然后重启数据库,再把3条记录删除,重新插入。
#4
mysql需要设置编码格式,要不会乱码的
#5
#6
楼主应该是乱码问题,统一一下格式就可以了
#7
肯定是编码问题,在进行数据库连接的时候设置characterEncoding=UTF-8如:“jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8”
#8
在java中使用的编码和mysql中使用的编码必须一致,在mysql中查看编码使用show variables like 'character_set_%';可以看数据库使用的字符编码
#9
我试过了,也没用
#10
这个也试过了,好像不行哦
#11
你要
先改表的编码,
然后把数据删掉,
重新添加(中文),再查看看.如果你改了表的编辑,原来的中文会在改后变成乱码,你查肯定也会是和没有修改前一样是乱码.
先改表的编码,
然后把数据删掉,
重新添加(中文),再查看看.如果你改了表的编辑,原来的中文会在改后变成乱码,你查肯定也会是和没有修改前一样是乱码.
#12
哦,是这样嘛,改了编码还要原来的数据删了,重新加数据是吧,我试试去~
#13
[img=Y)NM@OZ0VQP49PY9}3QK[NG][/img][img=L3E~MT4EWJY`L1ZFTU2%)U2][/img][img=@$~NCPMXD4665SWT908%2ZA][/img][img=%$3~MT6B8K9CX3R5GNP$SEK][/img][img=1Z`INI%`F1V0Y2@C]P(CO7B][/img][img=3%DPJS8%(MDO$T$W`1B3~N2][/img]
#14
我都试过了,你们说的方法,还是不行??怎么回事啊,我发的图片也看不了?~
#15
看不了,你先试试在Mysql的command里select出来是不是乱码的,先看数据库,再查程序.一步一步确定来找问题
| NULL |
| 中文 |
| 中文的 |
| NULL |
| NULL |
+--------+
5 rows in set (0.00 sec)
| NULL |
| 中文 |
| 中文的 |
| NULL |
| NULL |
+--------+
5 rows in set (0.00 sec)
#16
怎么回复不能发图片的?可以的话我发给你看看~
#17
[img=http://user.qzone.qq.com/184412656/infocenter#!app=2&via=QZ.HashRefresh&pos=1348890335][/img]
我这次在qq日志里发的图片,你们帮忙看看~按照你们说的也都改了,改重启也重启了,问题还是那样。
我这次在qq日志里发的图片,你们帮忙看看~按照你们说的也都改了,改重启也重启了,问题还是那样。
#18
#19
你的程序的编码方式应该是GBK的。你直接到查询出来后再转码吧
String newName = new String(name.getBytes(), "GBK"); 试试
String newName = new String(name.getBytes(), "GBK"); 试试
#20
不行,我把源码发出来,大家帮看看:
package com.login;
//import java.awt.BorderLayout;
//import java.awt.event.ActionEvent;
//import java.beans.Statement;
//import java.sql.DriverManager;
//import java.sql.ResultSet;
//
//import javax.swing.JApplet;
//import javax.swing.JButton;
//import javax.swing.JLabel;
//import javax.swing.JPanel;
//import javax.swing.JTextField;
//
//import com.sun.corba.se.pept.transport.Connection;
//import com.sun.org.apache.bcel.internal.generic.NEW;
//
//public class Login extends JApplet{
// private JTextField idTextField=new JTextField(10);
// private JTextField nameTextField=new JTextField(15);
// private JButton okButton=new JButton("确定");
// private java.sql.Statement stm;
// public void inint(){
// initializeDB();
// //监听事件
// okButton.addActionListener(
// new java.awt.event.ActionListener(){
// public void actionPerformed(ActionEvent e){
// okButton_actionPerformed(e);
// }
// });
// JPanel jPanel1=new JPanel();
// jPanel1.add(new JLabel("ID"));
// jPanel1.add(idTextField);
// jPanel1.add(new JLabel("用户名"));
// jPanel1.add(nameTextField);
// jPanel1.add(okButton);
// add(jPanel1,BorderLayout.NORTH);
// }
// private void initializeDB() {
// //加载驱动
// try {
// Class.forName("com.mysql.jdbc.Driver");
// System.out.println("Suceess!");
// java.sql.Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/books","scott","tiger");
// System.out.println("Suceess2");
// stm=connection.createStatement();
//
// } catch (Exception e) {
// // TODO: handle exception
// e.printStackTrace();
// }
// }
// private void okButton_actionPerformed(ActionEvent e) {
// // TODO Auto-generated method stub
// String ssnString=idTextField.getText();
// String courseID=nameTextField.getText();
// try {
// String queryString="";
// ResultSet resultSet=stm.executeQuery(queryString);
// if (resultSet.next()) {
// String lastNameString=resultSet.getString(1);
//
// } else {
//
// }
// } catch (Exception e2) {
// // TODO: handle exception
// e2.printStackTrace();
// }
// }
//}
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
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 java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
class Login extends JFrame implements ActionListener {
Container ct = null; // 存放容器对象
JFrame f = null;
JButton j1, j2;
JTextField t1;
JPasswordField t2;
JLabel jlable1, jlable2;
Color c;
JPanel jp1, jp2;
public Login() {
f = new JFrame("图书管理系统");
j1 = new JButton("确定");
j2 = new JButton("取消");
ct = f.getContentPane();// 返回此窗体的对象
jlable1 = new JLabel(" 用 户 名:");
jlable2 = new JLabel(" 用户密码:");
jp1 = new JPanel();
jp2 = new JPanel();
t1 = new JTextField(15);
t2 = new JPasswordField(15);
jp1.add(jlable1);
jp1.add(t1);
jp1.add(jlable2);
jp1.add(t2);
JLabel JL = new JLabel(
"<html><font color=#CC00FF size='7'>Welcome</font>",
SwingConstants.CENTER);
ct.add(JL, "North");
jp2.add(j1);
jp2.add(j2);
ct.add(jp1, "Center");
ct.add("South", jp2);
jp1.setBackground(new Color(200, 100, 200));
Toolkit kit = Toolkit.getDefaultToolkit();// 获取默认工具包
Dimension screen = kit.getScreenSize();// 获取屏幕的大小
int x = screen.width; // 取得显示器窗口的宽度
int y = screen.height; // 取得显示器窗口的高度
// setSize(x,y); //让系统窗口平铺整个显示器窗口
f.setSize(300, 300);
int xcenter = (x - 300) / 2;
int ycenter = (y - 300) / 2;
f.setLocation(xcenter, ycenter);// 显示在窗口*
f.setVisible(true);
// 注册事件监听器
// jlable1.add
j1.addActionListener(this);
j2.addActionListener(this);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// 验证用户和密码是否存在
@SuppressWarnings("deprecation")
public void confirm()
{
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.println("加载驱动程序失败!");
}
try{
boolean falg = false;
// Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/books","root","123456");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/books?user=root&password=123456&useUnicode=true&characEncoding=UTF-8");
Statement sql=con.createStatement();
String uname=t1.getText();
System.out.println("usame++++++++"+uname);
String Mima=t2.getText();
System.out.println("Mima+++++++++"+Mima);
String queryMima="select * from brimary where name='" + uname + "'and pw='" + Mima + "'";
ResultSet rs=sql.executeQuery(queryMima);
for(int i=1;i<100;i++){
if(true){
}
}
// ResultSet op=sql.executeQuery("select * from brimary where name='" + uname + "'and pw='" + Mima + "'");
if(rs.next()) {
System.out.println("----------" + rs.getString(1) +"----------" + rs.getString(2));
new Book(uname);
con.close();
}
else{
// JOptionPane.showMessageDialog(null,"该用户不存在","提示!",JOptionPane.YES_NO_OPTION);
System.out.println("----------" + rs.getString(1) +"----------" + rs.getString(2));
}
t1.setText("");
t2.setText("");
}
catch(SQLException g)
{ System.out.println("E Code"+g.getErrorCode());
System.out.println("E M"+g.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if(cmd.equals("确定")){
confirm();
}
else if(cmd.equals("取消")){
f.dispose();
}
}
public static void main(String args[]){
Login a=new Login();
new java.awt.print.Book();
}
}
package com.login;
//import java.awt.BorderLayout;
//import java.awt.event.ActionEvent;
//import java.beans.Statement;
//import java.sql.DriverManager;
//import java.sql.ResultSet;
//
//import javax.swing.JApplet;
//import javax.swing.JButton;
//import javax.swing.JLabel;
//import javax.swing.JPanel;
//import javax.swing.JTextField;
//
//import com.sun.corba.se.pept.transport.Connection;
//import com.sun.org.apache.bcel.internal.generic.NEW;
//
//public class Login extends JApplet{
// private JTextField idTextField=new JTextField(10);
// private JTextField nameTextField=new JTextField(15);
// private JButton okButton=new JButton("确定");
// private java.sql.Statement stm;
// public void inint(){
// initializeDB();
// //监听事件
// okButton.addActionListener(
// new java.awt.event.ActionListener(){
// public void actionPerformed(ActionEvent e){
// okButton_actionPerformed(e);
// }
// });
// JPanel jPanel1=new JPanel();
// jPanel1.add(new JLabel("ID"));
// jPanel1.add(idTextField);
// jPanel1.add(new JLabel("用户名"));
// jPanel1.add(nameTextField);
// jPanel1.add(okButton);
// add(jPanel1,BorderLayout.NORTH);
// }
// private void initializeDB() {
// //加载驱动
// try {
// Class.forName("com.mysql.jdbc.Driver");
// System.out.println("Suceess!");
// java.sql.Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/books","scott","tiger");
// System.out.println("Suceess2");
// stm=connection.createStatement();
//
// } catch (Exception e) {
// // TODO: handle exception
// e.printStackTrace();
// }
// }
// private void okButton_actionPerformed(ActionEvent e) {
// // TODO Auto-generated method stub
// String ssnString=idTextField.getText();
// String courseID=nameTextField.getText();
// try {
// String queryString="";
// ResultSet resultSet=stm.executeQuery(queryString);
// if (resultSet.next()) {
// String lastNameString=resultSet.getString(1);
//
// } else {
//
// }
// } catch (Exception e2) {
// // TODO: handle exception
// e2.printStackTrace();
// }
// }
//}
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
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 java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
class Login extends JFrame implements ActionListener {
Container ct = null; // 存放容器对象
JFrame f = null;
JButton j1, j2;
JTextField t1;
JPasswordField t2;
JLabel jlable1, jlable2;
Color c;
JPanel jp1, jp2;
public Login() {
f = new JFrame("图书管理系统");
j1 = new JButton("确定");
j2 = new JButton("取消");
ct = f.getContentPane();// 返回此窗体的对象
jlable1 = new JLabel(" 用 户 名:");
jlable2 = new JLabel(" 用户密码:");
jp1 = new JPanel();
jp2 = new JPanel();
t1 = new JTextField(15);
t2 = new JPasswordField(15);
jp1.add(jlable1);
jp1.add(t1);
jp1.add(jlable2);
jp1.add(t2);
JLabel JL = new JLabel(
"<html><font color=#CC00FF size='7'>Welcome</font>",
SwingConstants.CENTER);
ct.add(JL, "North");
jp2.add(j1);
jp2.add(j2);
ct.add(jp1, "Center");
ct.add("South", jp2);
jp1.setBackground(new Color(200, 100, 200));
Toolkit kit = Toolkit.getDefaultToolkit();// 获取默认工具包
Dimension screen = kit.getScreenSize();// 获取屏幕的大小
int x = screen.width; // 取得显示器窗口的宽度
int y = screen.height; // 取得显示器窗口的高度
// setSize(x,y); //让系统窗口平铺整个显示器窗口
f.setSize(300, 300);
int xcenter = (x - 300) / 2;
int ycenter = (y - 300) / 2;
f.setLocation(xcenter, ycenter);// 显示在窗口*
f.setVisible(true);
// 注册事件监听器
// jlable1.add
j1.addActionListener(this);
j2.addActionListener(this);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// 验证用户和密码是否存在
@SuppressWarnings("deprecation")
public void confirm()
{
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.println("加载驱动程序失败!");
}
try{
boolean falg = false;
// Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/books","root","123456");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/books?user=root&password=123456&useUnicode=true&characEncoding=UTF-8");
Statement sql=con.createStatement();
String uname=t1.getText();
System.out.println("usame++++++++"+uname);
String Mima=t2.getText();
System.out.println("Mima+++++++++"+Mima);
String queryMima="select * from brimary where name='" + uname + "'and pw='" + Mima + "'";
ResultSet rs=sql.executeQuery(queryMima);
for(int i=1;i<100;i++){
if(true){
}
}
// ResultSet op=sql.executeQuery("select * from brimary where name='" + uname + "'and pw='" + Mima + "'");
if(rs.next()) {
System.out.println("----------" + rs.getString(1) +"----------" + rs.getString(2));
new Book(uname);
con.close();
}
else{
// JOptionPane.showMessageDialog(null,"该用户不存在","提示!",JOptionPane.YES_NO_OPTION);
System.out.println("----------" + rs.getString(1) +"----------" + rs.getString(2));
}
t1.setText("");
t2.setText("");
}
catch(SQLException g)
{ System.out.println("E Code"+g.getErrorCode());
System.out.println("E M"+g.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if(cmd.equals("确定")){
confirm();
}
else if(cmd.equals("取消")){
f.dispose();
}
}
public static void main(String args[]){
Login a=new Login();
new java.awt.print.Book();
}
}
#21
#1
肯定是乱码了吧,看看编码是否统一
#2
看看你数据库属性 字符集 应该用utf8 -- UTF-8 Unicode
#3
编码方式不同意,mysql默认的编码是lan1
修改文件my.ini
C:\Program Files\MySQL\MySQL Server 5.1\my.ini
[client]和[mysqld]下面进行修改: default-character-set = utf8
然后重启数据库,再把3条记录删除,重新插入。
修改文件my.ini
C:\Program Files\MySQL\MySQL Server 5.1\my.ini
[client]和[mysqld]下面进行修改: default-character-set = utf8
然后重启数据库,再把3条记录删除,重新插入。
#4
mysql需要设置编码格式,要不会乱码的
#5
#6
楼主应该是乱码问题,统一一下格式就可以了
#7
肯定是编码问题,在进行数据库连接的时候设置characterEncoding=UTF-8如:“jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8”
#8
在java中使用的编码和mysql中使用的编码必须一致,在mysql中查看编码使用show variables like 'character_set_%';可以看数据库使用的字符编码
#9
我试过了,也没用
#10
这个也试过了,好像不行哦
#11
你要
先改表的编码,
然后把数据删掉,
重新添加(中文),再查看看.如果你改了表的编辑,原来的中文会在改后变成乱码,你查肯定也会是和没有修改前一样是乱码.
先改表的编码,
然后把数据删掉,
重新添加(中文),再查看看.如果你改了表的编辑,原来的中文会在改后变成乱码,你查肯定也会是和没有修改前一样是乱码.
#12
哦,是这样嘛,改了编码还要原来的数据删了,重新加数据是吧,我试试去~
#13
[img=Y)NM@OZ0VQP49PY9}3QK[NG][/img][img=L3E~MT4EWJY`L1ZFTU2%)U2][/img][img=@$~NCPMXD4665SWT908%2ZA][/img][img=%$3~MT6B8K9CX3R5GNP$SEK][/img][img=1Z`INI%`F1V0Y2@C]P(CO7B][/img][img=3%DPJS8%(MDO$T$W`1B3~N2][/img]
#14
我都试过了,你们说的方法,还是不行??怎么回事啊,我发的图片也看不了?~
#15
看不了,你先试试在Mysql的command里select出来是不是乱码的,先看数据库,再查程序.一步一步确定来找问题
| NULL |
| 中文 |
| 中文的 |
| NULL |
| NULL |
+--------+
5 rows in set (0.00 sec)
| NULL |
| 中文 |
| 中文的 |
| NULL |
| NULL |
+--------+
5 rows in set (0.00 sec)
#16
怎么回复不能发图片的?可以的话我发给你看看~
#17
[img=http://user.qzone.qq.com/184412656/infocenter#!app=2&via=QZ.HashRefresh&pos=1348890335][/img]
我这次在qq日志里发的图片,你们帮忙看看~按照你们说的也都改了,改重启也重启了,问题还是那样。
我这次在qq日志里发的图片,你们帮忙看看~按照你们说的也都改了,改重启也重启了,问题还是那样。
#18
http://user.qzone.qq.com/184412656/infocenter#!app=2&via=QZ.HashRefresh&pos=1348890335
晕这样不行!!那我发个链接吧
晕这样不行!!那我发个链接吧
#19
你的程序的编码方式应该是GBK的。你直接到查询出来后再转码吧
String newName = new String(name.getBytes(), "GBK"); 试试
String newName = new String(name.getBytes(), "GBK"); 试试
#20
不行,我把源码发出来,大家帮看看:
package com.login;
//import java.awt.BorderLayout;
//import java.awt.event.ActionEvent;
//import java.beans.Statement;
//import java.sql.DriverManager;
//import java.sql.ResultSet;
//
//import javax.swing.JApplet;
//import javax.swing.JButton;
//import javax.swing.JLabel;
//import javax.swing.JPanel;
//import javax.swing.JTextField;
//
//import com.sun.corba.se.pept.transport.Connection;
//import com.sun.org.apache.bcel.internal.generic.NEW;
//
//public class Login extends JApplet{
// private JTextField idTextField=new JTextField(10);
// private JTextField nameTextField=new JTextField(15);
// private JButton okButton=new JButton("确定");
// private java.sql.Statement stm;
// public void inint(){
// initializeDB();
// //监听事件
// okButton.addActionListener(
// new java.awt.event.ActionListener(){
// public void actionPerformed(ActionEvent e){
// okButton_actionPerformed(e);
// }
// });
// JPanel jPanel1=new JPanel();
// jPanel1.add(new JLabel("ID"));
// jPanel1.add(idTextField);
// jPanel1.add(new JLabel("用户名"));
// jPanel1.add(nameTextField);
// jPanel1.add(okButton);
// add(jPanel1,BorderLayout.NORTH);
// }
// private void initializeDB() {
// //加载驱动
// try {
// Class.forName("com.mysql.jdbc.Driver");
// System.out.println("Suceess!");
// java.sql.Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/books","scott","tiger");
// System.out.println("Suceess2");
// stm=connection.createStatement();
//
// } catch (Exception e) {
// // TODO: handle exception
// e.printStackTrace();
// }
// }
// private void okButton_actionPerformed(ActionEvent e) {
// // TODO Auto-generated method stub
// String ssnString=idTextField.getText();
// String courseID=nameTextField.getText();
// try {
// String queryString="";
// ResultSet resultSet=stm.executeQuery(queryString);
// if (resultSet.next()) {
// String lastNameString=resultSet.getString(1);
//
// } else {
//
// }
// } catch (Exception e2) {
// // TODO: handle exception
// e2.printStackTrace();
// }
// }
//}
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
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 java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
class Login extends JFrame implements ActionListener {
Container ct = null; // 存放容器对象
JFrame f = null;
JButton j1, j2;
JTextField t1;
JPasswordField t2;
JLabel jlable1, jlable2;
Color c;
JPanel jp1, jp2;
public Login() {
f = new JFrame("图书管理系统");
j1 = new JButton("确定");
j2 = new JButton("取消");
ct = f.getContentPane();// 返回此窗体的对象
jlable1 = new JLabel(" 用 户 名:");
jlable2 = new JLabel(" 用户密码:");
jp1 = new JPanel();
jp2 = new JPanel();
t1 = new JTextField(15);
t2 = new JPasswordField(15);
jp1.add(jlable1);
jp1.add(t1);
jp1.add(jlable2);
jp1.add(t2);
JLabel JL = new JLabel(
"<html><font color=#CC00FF size='7'>Welcome</font>",
SwingConstants.CENTER);
ct.add(JL, "North");
jp2.add(j1);
jp2.add(j2);
ct.add(jp1, "Center");
ct.add("South", jp2);
jp1.setBackground(new Color(200, 100, 200));
Toolkit kit = Toolkit.getDefaultToolkit();// 获取默认工具包
Dimension screen = kit.getScreenSize();// 获取屏幕的大小
int x = screen.width; // 取得显示器窗口的宽度
int y = screen.height; // 取得显示器窗口的高度
// setSize(x,y); //让系统窗口平铺整个显示器窗口
f.setSize(300, 300);
int xcenter = (x - 300) / 2;
int ycenter = (y - 300) / 2;
f.setLocation(xcenter, ycenter);// 显示在窗口*
f.setVisible(true);
// 注册事件监听器
// jlable1.add
j1.addActionListener(this);
j2.addActionListener(this);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// 验证用户和密码是否存在
@SuppressWarnings("deprecation")
public void confirm()
{
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.println("加载驱动程序失败!");
}
try{
boolean falg = false;
// Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/books","root","123456");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/books?user=root&password=123456&useUnicode=true&characEncoding=UTF-8");
Statement sql=con.createStatement();
String uname=t1.getText();
System.out.println("usame++++++++"+uname);
String Mima=t2.getText();
System.out.println("Mima+++++++++"+Mima);
String queryMima="select * from brimary where name='" + uname + "'and pw='" + Mima + "'";
ResultSet rs=sql.executeQuery(queryMima);
for(int i=1;i<100;i++){
if(true){
}
}
// ResultSet op=sql.executeQuery("select * from brimary where name='" + uname + "'and pw='" + Mima + "'");
if(rs.next()) {
System.out.println("----------" + rs.getString(1) +"----------" + rs.getString(2));
new Book(uname);
con.close();
}
else{
// JOptionPane.showMessageDialog(null,"该用户不存在","提示!",JOptionPane.YES_NO_OPTION);
System.out.println("----------" + rs.getString(1) +"----------" + rs.getString(2));
}
t1.setText("");
t2.setText("");
}
catch(SQLException g)
{ System.out.println("E Code"+g.getErrorCode());
System.out.println("E M"+g.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if(cmd.equals("确定")){
confirm();
}
else if(cmd.equals("取消")){
f.dispose();
}
}
public static void main(String args[]){
Login a=new Login();
new java.awt.print.Book();
}
}
package com.login;
//import java.awt.BorderLayout;
//import java.awt.event.ActionEvent;
//import java.beans.Statement;
//import java.sql.DriverManager;
//import java.sql.ResultSet;
//
//import javax.swing.JApplet;
//import javax.swing.JButton;
//import javax.swing.JLabel;
//import javax.swing.JPanel;
//import javax.swing.JTextField;
//
//import com.sun.corba.se.pept.transport.Connection;
//import com.sun.org.apache.bcel.internal.generic.NEW;
//
//public class Login extends JApplet{
// private JTextField idTextField=new JTextField(10);
// private JTextField nameTextField=new JTextField(15);
// private JButton okButton=new JButton("确定");
// private java.sql.Statement stm;
// public void inint(){
// initializeDB();
// //监听事件
// okButton.addActionListener(
// new java.awt.event.ActionListener(){
// public void actionPerformed(ActionEvent e){
// okButton_actionPerformed(e);
// }
// });
// JPanel jPanel1=new JPanel();
// jPanel1.add(new JLabel("ID"));
// jPanel1.add(idTextField);
// jPanel1.add(new JLabel("用户名"));
// jPanel1.add(nameTextField);
// jPanel1.add(okButton);
// add(jPanel1,BorderLayout.NORTH);
// }
// private void initializeDB() {
// //加载驱动
// try {
// Class.forName("com.mysql.jdbc.Driver");
// System.out.println("Suceess!");
// java.sql.Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/books","scott","tiger");
// System.out.println("Suceess2");
// stm=connection.createStatement();
//
// } catch (Exception e) {
// // TODO: handle exception
// e.printStackTrace();
// }
// }
// private void okButton_actionPerformed(ActionEvent e) {
// // TODO Auto-generated method stub
// String ssnString=idTextField.getText();
// String courseID=nameTextField.getText();
// try {
// String queryString="";
// ResultSet resultSet=stm.executeQuery(queryString);
// if (resultSet.next()) {
// String lastNameString=resultSet.getString(1);
//
// } else {
//
// }
// } catch (Exception e2) {
// // TODO: handle exception
// e2.printStackTrace();
// }
// }
//}
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
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 java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
class Login extends JFrame implements ActionListener {
Container ct = null; // 存放容器对象
JFrame f = null;
JButton j1, j2;
JTextField t1;
JPasswordField t2;
JLabel jlable1, jlable2;
Color c;
JPanel jp1, jp2;
public Login() {
f = new JFrame("图书管理系统");
j1 = new JButton("确定");
j2 = new JButton("取消");
ct = f.getContentPane();// 返回此窗体的对象
jlable1 = new JLabel(" 用 户 名:");
jlable2 = new JLabel(" 用户密码:");
jp1 = new JPanel();
jp2 = new JPanel();
t1 = new JTextField(15);
t2 = new JPasswordField(15);
jp1.add(jlable1);
jp1.add(t1);
jp1.add(jlable2);
jp1.add(t2);
JLabel JL = new JLabel(
"<html><font color=#CC00FF size='7'>Welcome</font>",
SwingConstants.CENTER);
ct.add(JL, "North");
jp2.add(j1);
jp2.add(j2);
ct.add(jp1, "Center");
ct.add("South", jp2);
jp1.setBackground(new Color(200, 100, 200));
Toolkit kit = Toolkit.getDefaultToolkit();// 获取默认工具包
Dimension screen = kit.getScreenSize();// 获取屏幕的大小
int x = screen.width; // 取得显示器窗口的宽度
int y = screen.height; // 取得显示器窗口的高度
// setSize(x,y); //让系统窗口平铺整个显示器窗口
f.setSize(300, 300);
int xcenter = (x - 300) / 2;
int ycenter = (y - 300) / 2;
f.setLocation(xcenter, ycenter);// 显示在窗口*
f.setVisible(true);
// 注册事件监听器
// jlable1.add
j1.addActionListener(this);
j2.addActionListener(this);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// 验证用户和密码是否存在
@SuppressWarnings("deprecation")
public void confirm()
{
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{
System.out.println("加载驱动程序失败!");
}
try{
boolean falg = false;
// Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/books","root","123456");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/books?user=root&password=123456&useUnicode=true&characEncoding=UTF-8");
Statement sql=con.createStatement();
String uname=t1.getText();
System.out.println("usame++++++++"+uname);
String Mima=t2.getText();
System.out.println("Mima+++++++++"+Mima);
String queryMima="select * from brimary where name='" + uname + "'and pw='" + Mima + "'";
ResultSet rs=sql.executeQuery(queryMima);
for(int i=1;i<100;i++){
if(true){
}
}
// ResultSet op=sql.executeQuery("select * from brimary where name='" + uname + "'and pw='" + Mima + "'");
if(rs.next()) {
System.out.println("----------" + rs.getString(1) +"----------" + rs.getString(2));
new Book(uname);
con.close();
}
else{
// JOptionPane.showMessageDialog(null,"该用户不存在","提示!",JOptionPane.YES_NO_OPTION);
System.out.println("----------" + rs.getString(1) +"----------" + rs.getString(2));
}
t1.setText("");
t2.setText("");
}
catch(SQLException g)
{ System.out.println("E Code"+g.getErrorCode());
System.out.println("E M"+g.getMessage());
}
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if(cmd.equals("确定")){
confirm();
}
else if(cmd.equals("取消")){
f.dispose();
}
}
public static void main(String args[]){
Login a=new Login();
new java.awt.print.Book();
}
}