简体   繁体   中英

Trying to connect to an online database using Intellij

I'm trying to establish a connecting using intellij and I can connect to it usiing the database maven class but when using the java class

static final String JBDC_DRIVER="com.mysql.jbdc.Driver";
    static final String DB_URL="jdbc:mysql://35.247.85.196:3302";
    static final String USER="Nick";
    static final String PASS="poop";

public static void main (String[] args)
{
Connection conn=null;
        Statement stmt=null;

        //reister jbdc driver
        try {
            Class.forName(JBDC_DRIVER);
            System.out.println("Connecting to the database...");
            conn=DriverManager.getConnection(DB_URL,USER,PASS);
            System.out.println("Connected to database successfully");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

} I get the exception

java.lang.ClassNotFoundException: com.mysql.jbdc.Driver
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at DataGenerator.main(DataGenerator.java:33)

and line 33 being

Class.forName(JBDC_DRIVER);

Try removing the Class.forName(JDBC_DRIVER) , add a import com.mysql.jdbc.*; onto your main class and also add the name of your database on the DB_URL like this:

static final String DB_URL="jdbc:mysql://35.247.85.196:3302/dataBaseName";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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