0
package net.codejava;

import java.sql.*;
class MysqlCon{

    public static void updateInDB(String num1)
    {
        try{
            Class.forName("jdbc:mysql://localhost:port/database");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:port/database","user","password");Statement stmt=con.createStatement();
    ..................

This is the code i'm using to connect to my databse . I have mysql-connector jar in the class path of my project in Intellij IDE. Have also added it in tomcat9/lib. Getting the below error

Output Exception

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
sujitha
  • 1
  • 2
  • I'm afraid it's going to be difficult to help you without you providing more information. Are you using Spring, Hibernate, JPA etc. ? If so, please edit the question to include how you are configuring this. (Of course, edit out anything sensitive such as passwords.) If you're not using something like Spring or Hibernate, please edit the question to include the code you are using to connect to the database. Please also edit your question to include the full stacktrace of the exception you are getting. – Luke Woodward Aug 15 '21 at 19:22
  • `Class.forName` is for loading classes, not for JDBC urls. Either remove it and rely on automatic driverloading, or specify the correct MySQL Connector/J driver class name (`com.mysql.cj.jdbc.Driver` or `com.mysql.jdbc.Driver`). – Mark Rotteveel Aug 16 '21 at 09:27

0 Answers0