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

  • Home
  • SEARCH
  • 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 6761349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:10:40+00:00 2026-05-26T14:10:40+00:00

My code compiles and runs fine in Eclipse, but when I try to make

  • 0

My code compiles and runs fine in Eclipse, but when I try to make it into a .jar it gives me a bunch of errors.

The code, the .bat file I use to compile into .jar and my error message can be found here:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.Scanner;
import com.mysql.jdbc.PreparedStatement;


public class Main
{
        private static Scanner scn = new Scanner(System.in);

        public static void main(String[] argv) throws Exception
        {
                Class.forName("com.mysql.jdbc.Driver");

                Main main = new Main();
                int choice = 0;

                System.out.println("\t\tWelcome !\n\n");

                System.out.print(
                                           "1. Get Data From the table \"testtable\"\n"+
                                           "2. Insert data into the table \"testtable\"\n"+
                                           "Your choice?: "
                                                  );
                choice = scn.nextInt();
                scn.nextLine();

                switch( choice )
                {
                case 1:
                        main.getInfo();
                        break;

                case 2:
                        main.insertInfo();
                        break;

                default:
                        System.out.print("Was neither 1 or 2. Terminating program...");
                }


        }

        private void getInfo() throws Exception
        {
                //Class.forName("com.mysql.jdbc.Driver");

                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb", "guest", "shahin33");
                PreparedStatement statement = (PreparedStatement) con.prepareStatement("SELECT * FROM testtable");
                ResultSet result = statement.executeQuery();

                System.out.println();

                System.out.println("USERNAME\tPASSWORD");
                while( result.next() )
                {
                        System.out.println(result.getString(1) + "\t\t" + result.getString(2));
                }

                result.close();
                con.close();
        }

        private void insertInfo() throws Exception
        {
                System.out.print("\nUsername: ");
                String username = scn.nextLine();

                System.out.print("Password: ");
                String password = scn.nextLine().toLowerCase();

                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb", "guest", "shahin33");
                PreparedStatement statement = (PreparedStatement) con.prepareStatement("INSERT INTO testtable VALUES(?,?)");
                statement.setString(1, username);
                statement.setString(2, password);
                statement.executeUpdate();

                System.out.println("\nUser information has been inserted to the database.\nRun the program again and chose 1 to see result.");
                statement.close();
                con.close();

        }
}

The .bat file I use to compile into a .jar:

@echo off

set /p fileName="Name for the file? Exclude .jar: "

copy *.java "Source Code"
javac *.java

jar -cvfm %fileName%.jar manifest.txt *.class "Source Code"

del *.class /f /q
del "Source Code" /f /q

My error message:

C:\Users\shahin\Desktop\JavaComp>Compile_N_Whatnot.bat
Name for the file? Exclude .jar: comonXXXXXX
Main.java
        1 fil(er) kopierad(e).
Main.java:5: error: package com.mysql.jdbc does not exist
import com.mysql.jdbc.PreparedStatement;
                     ^
Main.java:51: error: cannot find symbol
                PreparedStatement statement = (PreparedStatement) con.prepa
tement("SELECT * FROM testtable");
                ^
  symbol:   class PreparedStatement
  location: class Main
Main.java:51: error: cannot find symbol
                PreparedStatement statement = (PreparedStatement) con.prepa
tement("SELECT * FROM testtable");
                                               ^
  symbol:   class PreparedStatement
  location: class Main
Main.java:75: error: cannot find symbol
                PreparedStatement statement = (PreparedStatement) con.prepa
tement("INSERT INTO testtable VALUES(?,?)");
                ^
  symbol:   class PreparedStatement
  location: class Main
Main.java:75: error: cannot find symbol
                PreparedStatement statement = (PreparedStatement) con.prepa
tement("INSERT INTO testtable VALUES(?,?)");

My classpath:

C:\Program\Java\jdk1.7.\bin\;
C:\Users\shahin\Desktop\mysql-connector-java-5.1.18\com\mysql\jdbc\;
C:\Users\shahin\Desktop\mysql-connector-java-5.1.18\mysql-connector-java-5.1.18-bin.jar;
  • 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-26T14:10:40+00:00Added an answer on May 26, 2026 at 2:10 pm

    You need to set up the classpath to include the required jar files. At the least, the JDBC driver is not on the compilation classpath.

    I’d strongly recommend not using batch files for this in all but the most simple situations, at the least aim for an Ant build script. It knows a lot about how Java stuff is supposed to work, and makes these kinds of problems easier to solve.

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

Sidebar

Related Questions

Eclipse compiles and runs this jsp just fine but when I deploy to Sun
The following code compiles and runs fine with gcc. But i wondered if such
Please check this code out it compiles and runs absolutely fine.. The question is
I have some code that compiles and runs on MSVC++ but will not compile
I have the following code which compiles and runs fine under Visual Studio 2008
I have some code written in C++ that compiles and runs fine (with reasonable
The following code compiles and runs fine. void myInvokedMethod(string s) { Console.WriteLine(s); } void
This piece of code compiles and runs as expected on GCC 3.x and 4.x:
This code in a GUI application compiles and runs: procedure TForm1.Button1Click(Sender: TObject); begin Self
The code compiles without too much complaint, but the last step fails with the

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.