x_x_s_s 2021-09-07 20:39 采纳率: 0%
浏览 62

为什么我用idea连接mysql会一直报异常,我已经驱动包导进去了

img

package cn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import com.mysql.jdbc.Driver;

public class jdbc {
    public static void main(String[] args) throws  Exception {

                Class.forName("com.mysql.jdbc.Driver");
        System.out.println("数据库驱动加载成功");
        Connection conn = DriverManager.getConnection("jdbc:mysql//localhost:3306/girls", "root", "123456");
        System.out.println("创建连接成功");
        String sql="update admin set username= 9999 where id=1";
        Statement stmt = conn.createStatement();
        int count = stmt.executeUpdate(sql);
        System.out.println( count  );
        stmt.close();
        conn.close();
    }

}


  • 写回答

5条回答 默认 最新

  • CSDN专家-sinJack 2021-09-07 20:59
    关注

    url写错了。mysql后面少写了冒号:

    package cn;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import com.mysql.jdbc.Driver;
    public class jdbc {
        public static void main(String[] args) throws  Exception {
                    Class.forName("com.mysql.jdbc.Driver");
            System.out.println("数据库驱动加载成功");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/girls", "root", "123456");
            System.out.println("创建连接成功");
            String sql="update admin set username= 9999 where id=1";
            Statement stmt = conn.createStatement();
            int count = stmt.executeUpdate(sql);
            System.out.println( count  );
            stmt.close();
            conn.close();
        }
    }
    
    评论

报告相同问题?

问题事件

  • 创建了问题 9月7日

悬赏问题

  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
  • ¥15 io.jsonwebtoken.security.Keys
  • ¥15 急,ubuntu安装后no caching mode page found等
  • ¥15 联想交换机NE2580O/NE1064TO安装SONIC
  • ¥15 防火墙的混合模式配置
  • ¥15 Ubuntu不小心注销了要怎么恢复啊