Java DriverManager赢得';似乎没有连接数据库

Java DriverManager赢得';似乎没有连接数据库,java,mysql,Java,Mysql,我正在为客户机/服务器应用程序处理学校作业,似乎无法使用JDBC DriverManager进行连接。我已经为我正在使用的模式it351设置了驱动程序,看起来一切都井然有序,但它从来没有通过连接激发来告诉我它已连接。群众中有什么智慧的话吗?我确实在“服务”任务窗格中显示了驱动程序,并且保存了密码,因此不必与类共享。谢谢 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; impor

我正在为客户机/服务器应用程序处理学校作业,似乎无法使用JDBC DriverManager进行连接。我已经为我正在使用的模式it351设置了驱动程序,看起来一切都井然有序,但它从来没有通过连接激发来告诉我它已连接。群众中有什么智慧的话吗?我确实在“服务”任务窗格中显示了驱动程序,并且保存了密码,因此不必与类共享。谢谢

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.net.*;
import java.sql.*;

public class GUI extends JFrame
{
   private JButton custButton;
   private JButton prodButton;
   private JButton exitButton;
   private JPanel p1;
   private JPanel p2;
   private JPanel p3;
   private JTextArea data;
  // private String message = ""; // message from server
   private String localhost; // host server for this application

public GUI()
   {
      super( "Database Data Retrieval" );
      setSize(825, 800);
      setVisible(true);
      setLocationRelativeTo(null);
      setResizable(true);
      setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      Container c = new Container();
      add(c);
      c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));

      // create and add jpanels for components
      p1 = new JPanel(); //(new FlowLayout(FlowLayout.CENTER));
      c.add(p1);
      p2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
      c.add(p2);
      p3 = new JPanel(new FlowLayout(FlowLayout.CENTER));
      c.add(p3);

      data = new JTextArea(35, 70);
      JScrollPane dataScroll = new JScrollPane(data);
      dataScroll.setPreferredSize(null);
      p1.add(data);
      p1.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
      data.setBorder(BorderFactory.createLineBorder(Color.black));
      data.setVisible(true);

      // create buttons
      p2.setBorder(BorderFactory.createTitledBorder( null, "Database Controls"));
      custButton = new JButton( "Retrieve Customer Data");
      p2.add (custButton);
      p2.add(Box.createRigidArea(new Dimension(50,0)));
      prodButton = new JButton( "Retrieve Product Data" );
      p2.add(prodButton);
      p2.add(Box.createVerticalGlue());
      p2.add(Box.createHorizontalGlue());
      exitButton = new JButton ("    Exit    ");
      p3.add(exitButton);
      p3.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));

// register events for buttons
ButtonHandler handler = new ButtonHandler();
      custButton.addActionListener( handler );
      prodButton.addActionListener( handler );
      exitButton.addActionListener( handler );
}


   private void displayMessage( final String messageToDisplay )
   {
      SwingUtilities.invokeLater(
         new Runnable()
         {
            public void run() // updates displayArea
            {
               data.append( messageToDisplay );
            } // end method run
         }  // end anonymous inner class
      ); // end call to SwingUtilities.invokeLater
   } // end method displayMessage

   private void connect()
   {
       Connection conn = null;
       try
                {
                Class.forName("com.mysql.jdbc.Driver"); 
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/it351?zeroDateTimeBehavior=convertToNull", "root", ""); //Connect
                    displayMessage("******* Connection created successfully *******"); //informs user of connection 
            }           
             catch (Exception err)
                {
                }
   }

   private class ButtonHandler implements ActionListener 
   {
      @Override
      public void actionPerformed( ActionEvent event )
      {         
         if (event.getSource() == custButton)         
         {   
             displayMessage( "******* Attempting connection *******\n" );
             connect();           
         }


         if (event.getSource() == prodButton)
         {                 

         }



         if (event.getSource() == exitButton)
         {
             System.exit(0);
         }

    }// end of actionperformed
}// end of buttonhandler 

}// end of GUI class

也许打印您的异常以查看出了什么问题……我没有收到异常。它只是在显示“正在尝试连接”后停止,其他情况不会发生。没有错误,什么都没有……如果你抓住了它却忽略了它,你怎么知道没有例外?如果在“尝试连接”后没有打印任何内容,您肯定会得到一个异常。java.lang.ClassNotFoundException:com.mysql.jdbc.Driver我想它告诉我它找不到驱动程序,但我读到的所有关于它的内容都让我很困惑。您必须将驱动程序添加到您的类路径中。