程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> java-數據庫連接不上,一直報錯

java-數據庫連接不上,一直報錯

編輯:編程解疑
數據庫連接不上,一直報錯

各位哥哥姐姐,能幫我一下嗎?我java數據庫連接不上。
我的是mysql 5.0 java 4.2
數據庫是5.1.36
網上說把jar包放在lib,我不知道放哪裡?
希望各位能指教一下我新手。謝謝·急!!
package denglu;

import gongyong.DaoConn;
import gongyong.SaveUserInfo;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

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 com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;

public class loginchuankou extends JFrame{
public DaoConn daoconn=new DaoConn();

private JButton guanbi=new JButton("退出");
private JButton Queding=new JButton("登錄");

private JPasswordField mimakuang=new JPasswordField(20);
private JTextField yonghumingkuang=new JTextField(20);

private JLabel yonghubiaoqian=new JLabel();

private JLabel mimabiaoqian=new JLabel();



public loginchuankou(){
    setTitle("系統登錄");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);




    setBounds(200,200,300,180);
//  setResizable(false);
    JPanel dengluchuan=new JPanel();
    getContentPane().add(dengluchuan,BorderLayout.CENTER);
    setVisible(true);




    yonghubiaoqian.setText("用戶名");
    dengluchuan.add(yonghubiaoqian);

    dengluchuan.add(yonghumingkuang);


    dengluchuan.add(Queding);

    mimabiaoqian.setText("密碼");
    dengluchuan.add(mimabiaoqian);

    dengluchuan.add(yonghumingkuang);

    dengluchuan.add(mimakuang);

    dengluchuan.add(guanbi);
    //鍵盤
    guanbi.addMouseListener(new MouseAdapter(){

        public void mouseClicked(final MouseEvent e){
            System.exit(0);
        }

            });

    Queding.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent evt) {            
            Queding(evt);         
                        }   
        });

    /////

}

protected void Queding(ActionEvent evt) {
    Connection conn = null;           //????
    Statement st = null;                
    ResultSet rs = null;   
    try {
        conn =(Connection) daoconn.getConn();           
        st = (Statement) conn.createStatement();    

        String user=yonghumingkuang.getText().trim();
        String pw=new String(mimakuang.getPassword()).trim();

        String sql="  select * from user where username='"+ user + "' and password= '"+ pw + "'  ";

        rs=(ResultSet) st.executeQuery(sql);

        if(rs.next() && rs.getString("username")!=null){
            SaveUserInfo.setuserName(user);
            SaveUserInfo.setpassword(pw);
            System.out.print("成功");
        }else{
            System.out.print("失敗");
        }
    } catch (Exception e) {

        e.printStackTrace();
    }finally{
    }

}//Queding

}//gouzao

報錯如下:
java.lang.ClassNotFoundException: com.mysql.jdbc.Drive
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at gongyong.DaoConn.getConn(DaoConn.java:8)
at denglu.loginchuankou.Queding(loginchuankou.java:105)
at denglu.loginchuankou$2.actionPerformed(loginchuankou.java:89)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:720)
at java.awt.EventQueue$4.run(EventQueue.java:718)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

最佳回答:


右鍵-》屬性後,在彈出框中選擇
圖片說明
戰鼓最右邊的紅框,然後選擇你的jar

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved