简体   繁体   English

找不到合适的驱动程序-SQLException JDBC

[英]No suitable driver found -SQLException JDBC

I just started to learn JDBC. 我刚刚开始学习JDBC。 I'm trying to connect to my MySQL database. 我正在尝试连接到我的MySQL数据库。 This is my code: 这是我的代码:

    import java.io.*;
        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;
        import java.sql.*;
        public class Test2{
                public static void main(String[] args){
                        try{
                                Class.forName("com.mysql.jdbc.Driver");
                                Connection con = DriverManager.getConnection("jbdc:mysql://localhost:3306/data","root","
****");
                                Statement stmt = con.createStatement();
                                ResultSet rs = stmt.executeQuery("SELECT * FROM details");
                                while(rs.next()){
                                        System.out.println(rs.getString(1)+" "+rs.getString(2));
                                }
                                con.close();
                        }
                        catch (Exception e){
                                System.out.println(e);
                        }

    }
    }

I've checked other stackoverflow answers but they don't seem to resolve the problem. 我检查了其他stackoverflow答案,但它们似乎无法解决问题。 I've added the jar file correctly.I've also registered the drive.These were the answers I got when I searched the web. 我已经正确添加了jar文件,还注册了驱动器,这是我在网上搜索时得到的答案。

Looks like you have misprint in database URL. 看起来您在数据库URL中打印有误。 Should be 应该

jdbc

instead of 代替

jbdc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM