skip to Main Content

enter image description here

I am able to import other packages like java.io to eclipse but, I am unable to import java.sql to my project in eclipse. What could be the reason?

I don’t know how to proceed. I have tried a couple of things, but none of them worked out for me.

2

Answers


  1. Can you add sql jar in classpath in :-

    Download Jar
    [http://www.java2s.com/Code/Jar/s/Downloadsqljar.htm]

    Adding in classpath
    [https://www.janbasktraining.com/community/sql-server/how-to-import-a-jar-file-in-eclipse]

    Login or Signup to reply.
  2. The java.sql package is included as part of every implementation of Java SE. There is no need to add JARs to your project for the java.sql API.

    You do need to add a JAR for a JDBC driver implementing JDBC, a driver specific to your database of choice such as MySQL or Postgres.

    Usually we include a JDBC driver as a dependency managed by Maven or Gradle. If you are not using a dependency manager, you will need to manually add the JDBC driver.

    Given your screenshot, I suspect that either you have installed a JRE rather than a full JDK, or your JDK is somehow corrupted. I suggest you delete your current JRE or JDK and download/install a fresh one. Tip: SDKMAN!. Java 17 is the current long-term support version.

    Also, I suggest you skip the JPA/Jakarta Persistence and the Hibernate until you get the basics of a database engine and database connection working. Make a simple little throwaway project to practice.

    If you search Stack Overflow you will find full example apps already written for connecting to a database, creating a table, populating the table, and retrieving from the table. Some were even written by me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search