Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: The package java.sql is not accessible

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default The package java.sql is not accessible

    Hello!

    After some time trying to make new project, but stuck in very beginning.

    The problem is that import does not see java library: The package java.sql is not accessible
    mysql-connector-java-8.0.18.jar is added through Build path configuration.

    Is there problem with mysql-connector-java-8.0.18.jar importing?

    Here is code:

    package newPackage;
    import java.sql.*;
     
     
    public class Piegades {
     
    public static void main(String[] args) throws Exception{
     
    		String url = "jdbc:mysql://localhost:3306/testdb";
    		String user = "root";
    		String password = "password";
     
    		Class.forName("com.mysql.cj.jdbc.Driver");
    		Connection con = DriverManager.getConnection(url, user, password);
    		System.out.println("Connection made");
    		con.close();
    		System.out.println("Connection closed!");
    	}
     
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: The package java.sql is not accessible

    Please copy the full text of the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The package java.sql is not accessible

    This is what I get on Run command:

    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Connection cannot be resolved to a type
    DriverManager cannot be resolved

    at piegades4/newPackage.Piegades.main(Piegades.java:14)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: The package java.sql is not accessible

    What IDE and JDK are you using? What is on the commandline when you compile the program?
    Why do you run the program if it has compiler errors?

    The code compiles without errors for me.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The package java.sql is not accessible

    Eclipse and JDK 12.

    I didn't run from commandline, but from Eclipse. I run it just to see more of error message. As I understand the problem is in fact that import java line is not seeing jova libraries...

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: The package java.sql is not accessible

    Sorry, I do not use Eclipse and don't know how to configure it.

    Try doing the compile from the commandline to see if it compiles there.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The package java.sql is not accessible

    I feel silly, but I solved problem my self. I made project from scrach and only thing I did another way – in New java project window in Project layout section this time instead of "Create separate folders for sources and class files" I used "Use project foler as root for sources and class files".

Similar Threads

  1. how to import/ access classes created in one package in another package
    By ydandurkar in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 11th, 2014, 11:12 AM
  2. Replies: 4
    Last Post: November 8th, 2012, 07:55 AM
  3. Replies: 1
    Last Post: March 16th, 2012, 12:23 PM
  4. Simple package problem, package does not exist error
    By Farmer in forum Object Oriented Programming
    Replies: 3
    Last Post: August 23rd, 2011, 11:18 AM
  5. object not accessible
    By sheikhms60 in forum Object Oriented Programming
    Replies: 1
    Last Post: February 22nd, 2010, 07:37 PM