Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6909705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:43:23+00:00 2026-05-27T08:43:23+00:00

I’m having trouble working out why java can’t see my mysql driver: I’ve downloaded

  • 0

I’m having trouble working out why java can’t see my mysql driver:

  • I’ve downloaded the driver .jar from the mysql website
  • I’ve added the jar to my runtime classpath
  • I can confirm the jar is on the classpath, by printing out the relevant system property

But I’m still getting ClassNotFound Exceptions. Is there anything else I need to be doing?

class example:

package org.rcz.dbtest;

import java.sql.*;

public class DB {

    private Connection connect = null;
    private Statement stmt = null;
    private PreparedStatement prepared = null;
    private ResultSet rset = null;
    private String driverClassName = "com.myqsl.jdbc.Driver";
    private String jdbcUrl = "jdbc:mysql://localhost/ctic_local?user=root&password=server";
    private String queryString;

    public DB(String query)
    {
        System.out.println(System.getProperty("java.class.path"));
        queryString = query;
    }

    public void readFromDatabase()
    {
        try
        {
            Class.forName(driverClassName);
            connect = DriverManager.getConnection(jdbcUrl);
            stmt = connect.createStatement();
            rset = stmt.executeQuery(queryString);
            writeResultSet(rset);
        }
        catch (ClassNotFoundException cex)
        {
            System.out.println("Could not find mysql class");
        }
        catch(SQLException sqex)
        {

        }
    }

    private void writeResultSet(ResultSet resultSet) throws SQLException {
        // ResultSet is initially before the first data set
        while (resultSet.next()) {
            // It is possible to get the columns via name
            // also possible to get the columns via the column number
            // which starts at 1
            // e.g. resultSet.getSTring(2);
            String user = resultSet.getString("name");
            String comment = resultSet.getString("comment");
            System.out.println("User: " + user);
            System.out.println("Comment: " + comment);
        }
    }



}

My main class simply passes the query into the DB class:

package org.rcz.dbtest;

import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException
    {
        String qstring = "SELECT * FROM comments";
        new DB(qstring).readFromDatabase();
        System.in.read();
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:43:24+00:00Added an answer on May 27, 2026 at 8:43 am

    You’ve a typo in the driver class name.

    private String driverClassName = "com.myqsl.jdbc.Driver";
    

    it should be

    private String driverClassName = "com.mysql.jdbc.Driver";
    // -------------------------------------^
    

    Unrelated to the concrete problem, holding DB resources like Connection, Statement and ResultSet as an instance variable of the class is a bad idea. You need to create, use and close them in the shortest possible scope in a try-finally block to prevent resource leaking. See also among others this question/answer: When my app loses connection, how should I recover it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.