使用的驱动程序不对,或者是驱动程序没有拷贝到你的WEB INF/LIB文件夹里。

解决方案 »

  1.   

    你是就这段程序不行还是一直就没能成功地联结上mysql呢?
    如果是一直没连接上我觉得一概是你的设置的问题。
      

  2.   

    giftxi我的驱动程序拷到你说的目录里了但还是不行,怎么办?
      

  3.   

    真搞不懂怎么这么多人都用这种方法,明明可以下一个.jar包放到common\lib下就可以连上了,还费这么大劲弄,去看一下以前的贴子还有("jdbc:mysql//192.168.85.119/weboa?user=user&password=sa");
    没有把mysql的端口号写上
    ("jdbc:mysql//192.168.85.119:3306/weboa?user=user&password=sa");
      

  4.   

    wbs0770我按你说的做了还是提示NO SUITABLE DRIVER怎么办?
      

  5.   

    你如果用的是tomcat,你要把mysql的jdbc驱动放到
    %TOMCAT_HOME%/common/lib下
    再用这种方式连数据库。
    ("jdbc:mysql//192.168.85.119:3306/weboa?user=user&password=sa");
      

  6.   

    是你的驱动没有加载成功,你是不是没有jar的驱动啊?没有的话,我发一个给你吧,文件不大然后你把它放到common\lin下,在mysql里建库和表就好了
      

  7.   

    这是一个很简单的连接mysql数据库的代码
    <%@ page contentType="text/html;charset=gb2312" %>
    <html> <head>
      <title>使用JDBC连接到数据库</title>
     </head>
      
     <body>
     <center>
     <%@ page import="java.sql.*"%>
     <%
       String driver="org.gjt.mm.mysql.Driver";
       String url="jdbc:mysql://localhost:3306/family";//family是你在数据名
       String userID="root";
       String passwd="";   try 
       {
        Class.forName(driver);
       } 
       catch(Exception e)
       {
        out.println("无法载入"+driver+"驱动程序!");
        e.printStackTrace();
       }
       try
       { 
        Connection DBcon=DriverManager.getConnection(url,userID,passwd);
        if(!DBcon.isClosed())
          out.println("成功地连接至数据库!");
        DBcon.close();
       }
       catch(SQLException SQLe)
       {
        out.println("无法连接至数据库!");
       }
       
     %>
     </center>
     </body>
    </html>
      

  8.   

    偶想用java程序来连接mysql,用下面的程序可以么?怎么执行后出错啊:(
    import java.sql.*;public class MySqlConnect
    {
    public static void main(String[] args)
    {
    //声名
    Connection Conn;
    Statement Stmt;
    ResultSet RS;
    String url = "jdbc:mysql//localhost/test";
    String name = "test";
    String pwd = "test";
    String sql = "select * from test"; try
    {
    // The newInstance() call is a work around for some
    // broken Java implementations
    Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 

    Conn = DriverManager.getConnection(url,name,pwd);
    // Do something with the Connection Stmt = Conn.createStatement();
           
            RS = Stmt.executeQuery(sql);
    Conn.close();
    }
    catch(Exception E)
    {
    System.out.print(E);
    }
    }
    }出错信息:
    java.sql.SQLException: No suitable driver
      

  9.   

    我已经将C:\j2sdk1.4.2_01\jdbc\mm.mysql.jdbc-1.2b\mysql_comp.jar加到我的classpath中了
      

  10.   

    楼上的你没看前面留言吧String url = "jdbc:mysql//localhost/test";
    一样少个mysql的端口号
    String url = "jdbc:mysql//localhost:3306/test";
    我看你的其它代码好像没有错误吧,我没有用java连过