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 7921265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:31:11+00:00 2026-06-03T16:31:11+00:00

I’m currently writing a jdbc client-server socket application in java. I’ve been having a

  • 0

I’m currently writing a jdbc client-server socket application in java. I’ve been having a bit of trouble initializing jdbc as i’m not using an ide, just a text editor and jdk. I have put my jdbc driver in my jdk and jre classpaths C:\Program Files\Java\jdk1.6.0_20\jre\lib\ext and \jre\lib\ext . I also renamed the jar to com.mysql.jdbc.driver , but I have still had no luck. Is this a problem with the driver not being found or is it something else?

Here is my error:

C:\Users\imallin\My Documents>java Provider
Waiting for connection
Connection received from 127.0.0.1
server>Hi welcome to the Cyfieithu Eadar-Theangachadh translation server, please
enter a command. Type cmd to see a list of commands
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at Provider.insertData(Provider.java:82)
    at Provider.run(Provider.java:40)
    at Provider.main(Provider.java:118)

Here is my code:

import java.io.*;
import java.net.*;
import java.util.Scanner;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Provider{
ServerSocket providerSocket;
Socket connection = null;
ObjectOutputStream out;
ObjectInputStream in;
String message;
Connection con;
Provider(){}
void run()
{
        Console c = System.console();
    if (c == null) {
        System.err.println("No console.");
        System.exit(1);
    }
    try{
        //1. creating a server socket
        providerSocket = new ServerSocket(2004, 10);
        //2. Wait for connection
        System.out.println("Waiting for connection");
        connection = providerSocket.accept();
        System.out.println("Connection received from " + connection.getInetAddress().getHostName());
        //3. get Input and Output streams
        out = new ObjectOutputStream(connection.getOutputStream());
        out.flush();
        in = new ObjectInputStream(connection.getInputStream());
                        sendMessage("Hi welcome to the Cyfieithu Eadar-Theangachadh translation server, please enter a command. Type cmd to see a list of commands");
        //4. The two parts communicate via the input and output streams
        do{
            try{
                                    insertData();

            message = (String) in.readObject();
            System.out.println("client>" + message);
                                if (message.equals("register"))
                    sendMessage("first name?");
                    String firstName = (message);
                    sendMessage("first name = " + firstName);
                    insertData();
                                if (message.equals("listlanguages"))
                                sendMessage("English \n Thai \n Geordia \n Gaelic \n Welsh \n Gaelic \n Urdu \n Polish \n Punjabi \n Cantonese \n Mandarin");
                    if (message.equals("bye"))
                    sendMessage("bye");
                    }
            catch(ClassNotFoundException classnot){
                System.err.println("Data received in unknown format");
            }
            catch (Exception e){
            System.err.println("Error: " + e.getMessage());
            }
        }while(!message.equals("bye"));
    }
    catch(IOException ioException){
        ioException.printStackTrace();
    }
    finally{
        //4: Closing connection
        try{
            in.close();
            out.close();
            providerSocket.close();
        }
        catch(IOException ioException){
            ioException.printStackTrace();
        }
    }
}
    private void insertData()
{

    try
    {
        Class.forName("com.mysql.jdbc.Driver");


        con = DriverManager.getConnection(
                "jdbc:mysql://localhost/translator","root","");

String sql = "Insert INTO users (ID, firstName) VALUES ('123','123')";

        Statement statement = con.createStatement();

        statement.execute(sql);


    }
                    catch (Exception e){
            System.err.println("Error: " + e.getMessage());
            }
    }


void sendMessage(String msg)
{
    try{
        out.writeObject(msg);
        out.flush();
        System.out.println("server>" + msg);
    }
    catch(IOException ioException){
        ioException.printStackTrace();
    }
}

public static void main(String args[])
{
    Provider server = new Provider();
    while(true){
        server.run();
    }
}
}
  • 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-06-03T16:31:14+00:00Added an answer on June 3, 2026 at 4:31 pm

    Like other answers have hinted already, the jdbc Jar is not on your classpath.

    To fix this, you need to declare, when running your Java main file, that it should use that Jar, by doing:

    java -cp "nameOfJar.jar" Provider
    

    This is assuming that your jar is on the same dir as your Provider file, if not you should specify the path to it.

    It’s totally optional, but I like having a directory named “lib” where I put all the jars I need to run my project, then you can add to classpath by doing:

    java -cp "./lib/*;." NameOfJavaClassWithMain
    

    Ultimately, you might end up having several directories or jars that you need to add to your classpath, you do this by using the ; (: in linux) separator, like:

    java -cp "./lib/*;./conf/configurationFile.properties;." NameOfJavaClassWithMain
    

    If your .class is not on one of the Jars, you might have to add the local directory to your classpath:

    java -cp "./lib/*;." NameOfJavaClassWithMain
    

    If you have a package declaration on your class (you should), you need to reference the class by that fully classified name (package+ClassName), like so:

    java -cp "./lib/*;." my.package.NameOfJavaClassWithMain
    
    • 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
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.