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.
2
Answers
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]
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 thejava.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.