求指教
连接数据库之后出现问题:java.net.ConnectException: Connection timed out: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.bookclient.control.ConnectServer.<init>(ConnectServer.java:18)
at com.bookclient.view.BookClientLogin.actionPerformed(BookClientLogin.java:106)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.NullPointerException
at com.bookclient.control.ConnectServer.sendMessage(ConnectServer.java:28)
at com.bookclient.view.BookClientLogin.actionPerformed(BookClientLogin.java:109)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
--------------------编程问答-------------------- 源代码为:package com.bookclient.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
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 com.bookclient.control.ConnectServer;
import com.common.Message;
public class BookClientLogin extends JFrame implements ActionListener{
/**
* @param args
*/
private JLabel background;
private ImageIcon backpicture;
private JPanel p;
private JPanel p1;
private JPanel p2;
private JPanel p3;
private JPanel p4;
private JLabel id;
private JLabel pass;
private JButton loginbutton;
private JButton registerbutton;
private JTextField itf;
private JPasswordField ptf;
public BookClientLogin(){
super("欢迎使用山财大图书馆个人信息系统:");
backpicture=new ImageIcon("./images/LoginBackground.jpg");
background=new JLabel(backpicture);
background.setBounds(0, 0, backpicture.getIconWidth(), backpicture.getIconHeight());
itf=new JTextField(10);
ptf=new JPasswordField(10);
loginbutton=new JButton("登录");
registerbutton=new JButton("注册");
loginbutton.addActionListener(this);
registerbutton.addActionListener(this);
loginbutton.setForeground(Color.orange);
registerbutton.setForeground(Color.orange);
id=new JLabel("帐号:");
pass=new JLabel("密码:");
id.setForeground(Color.orange);
pass.setForeground(Color.orange);
p1=new JPanel();
p1.setBounds(100,50,200,120);
p1.setLayout(new BorderLayout());
p2=new JPanel();
p2.setLayout(new FlowLayout());
p3=new JPanel();
p3.setLayout(new FlowLayout());
p4=new JPanel();
p4.setLayout(new FlowLayout());
p2.add(id);
p2.add(itf);
p3.add(pass);
p3.add(ptf);
p4.add(loginbutton);
p4.add(registerbutton);
p1.add(p2,BorderLayout.NORTH);
p1.add(p3,BorderLayout.CENTER);
p1.add(p4,BorderLayout.SOUTH);
p=(JPanel)this.getContentPane();
p.setLayout(null);
p.setOpaque(false);
p1.setOpaque(false);
p2.setOpaque(false);
p3.setOpaque(false);
p4.setOpaque(false);
p.add(p1);
this.getLayeredPane().setLayout(null);
this.getLayeredPane().add(background,new Integer(Integer.MIN_VALUE));
this.setBounds(350,200,backpicture.getIconWidth(),backpicture.getIconHeight());
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new BookClientLogin().setVisible(true);
}
@Override
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource()==loginbutton){
if(itf.getText().trim().equals("")){
JOptionPane.showMessageDialog(this, "请输入您的登录账号!",
"输入有误!",JOptionPane.WARNING_MESSAGE);
}
else if(String.valueOf(ptf.getPassword()).trim().equals("")){
JOptionPane.showMessageDialog(this, "请输入您的登录密码!",
"输入有误!",JOptionPane.WARNING_MESSAGE);
}
else{
Message mes=new Message();
mes.setFlag(2); //2表示要登录
ConnectServer cs=new ConnectServer(mes);
mes.setUserid(Integer.parseInt(itf.getText().trim()));
mes.setUserpassword(String.valueOf(ptf.getPassword()).trim());
cs.sendMessage();
Message mes1=cs.getMessage();
if(mes1.isOk()){
new ClientMain(Integer.parseInt(itf.getText().trim())).setVisible(true);
this.dispose();
}else{
JOptionPane.showMessageDialog(this,
"帐号或者密码错误!");
}
}
}
if(arg0.getSource()==registerbutton){
new ClientRegister().setVisible(true);
}
}
}
--------------------编程问答-------------------- 连接超时,检查下网络连接先 --------------------编程问答-------------------- 连接超时,看下服务端开启没 --------------------编程问答-------------------- 同楼上的。。。
补充:Java , Eclipse