Zulfi,
you will need to add the MySQL JDBC Driver to the classpath (or the
program you are running).
And maybe you will want to look for a General Java Programming Forum or
List. Apache Netbeans is meant for concerns about the IDE.
Good luck and regards
Andreas
On Wed, 2023-08-09 at 04:22 +0000, Zulfi Khan wrote:
> 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.
>