The Java classe driver Is changed.

The new driver class Is:
 com.mysql.cj.jdbc.Driver


Class.forName("com.mysql.cj.jdbc.Driver")


https://stackoverflow.com/questions/52032739/loading-class-com-mysql-jdbc-driver-this-is-deprecated-the-new-driver-class

Il mer 9 ago 2023, 06:23 Zulfi Khan <zulfi6...@yahoo.com.invalid> ha
scritto:

> Hi,
>
> Mysql driver error on Apachi netbeans 18.0
>
>
> Hi,
>
> I am working on ubuntu 18.04. mysql version is:
>
> mysql Ver 14.14 Distrib 5.7.42, for Linux (x86_64) using EditLine wrapper
>
>
> I have written the following code for connecting with database:
>
> import java.sql.Connection;
>
> import java.sql.DriverManager;
>
> import java.sql.SQLException;
>
> import java.sql.*;
>
> public class Dbconnect {
>
> boolean connect(){
>
> Connection con = null;
>
> System.out.println("Starts1...");
>
> try {
>
> System.out.println("Starts2...");
>
> Class.forName("com.mysql.jdbc.Driver");
>
> con = DriverManager.getConnection("jdbc:mysql://ebookshop", "root", "");
>
> System.out.println("Starts3...");
>
> if (!con.isClosed()){
>
> System.out.println("Successfully connected to MySQL server...");
>
> Statement stmt = con.createStatement();
>
> String sql = "select * from books";
>
> ResultSet rs = stmt.executeQuery(sql);
>
> String title;
>
> String author;
>
> float price;
>
> int qty;
>
> while(rs.next()){
>
> title = rs.getString("title");
>
> author = rs.getString("author");
>
> price = rs.getFloat("price");
>
> System.out.println("title ="+title+"author="+author+"price="+price);
>
> }
>
> }
>
> } catch(Exception e) {
>
> System.err.println("Exception: " + e.getMessage());
>
> } finally {
>
> try {
>
> if (con != null){
>
> con.close();
>
> return true;
>
> }
>
> } catch(SQLException e) {}
>
> }
>
> return false;
>
> }
>
>
> I am getting the following error:
>
>
> Starts1...
>
> Exception: com.mysql.jdbc.Driver
>
> Starts2...
>
> BUILD SUCCESSFUL (total time: 13 seconds)
>
>
> Somebody, please guide me.
>
>
> Zulfi.
>
>

Reply via email to