1

I have the code

package com.mycompany.mavenproject1;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;

 /**
 *
 * @author aleksandar
 */
public class Mavenproject1{

    public static void main(String[] args) {
        String uri = "jdbc:mysql://localhost:3306/test";
        try{
            Connection conn = DriverManager.getConnection(uri, "root", "Miskin@1982");
            Statement stmt = conn.createStatement();
       
        }catch(SQLException e){
            System.out.println(e.getMessage());
        }
    }
}  

I have in MySQL database test.

I have installed com.mysql.cj.jdbc.Driver in my Connector/J driver and I make a connection, but exception is still thrown.

my pom.xml is

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>mavenproject1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <exec.mainClass>com.mycompany.mavenproject1.Mavenproject1</exec.mainClass>
    </properties>
</project>
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

0 Answers0