JDBC с классом VSCODE не найденJAVA

Программисты JAVA общаются здесь
Anonymous
JDBC с классом VSCODE не найден

Сообщение Anonymous »

У меня серьезные проблемы с созданием проекта Java с кодом VS с добавлением «mysql-connector-java-8.0.21.jar».
Я сделал следующие шаги: < /p>

Библиотеки ". Извлечение моего кода: < /p>

Код: Выделить всё

import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SimpleJDBCApplication {

static final String DB_URL = "jdbc:mysql://localhost:3306/company";
static final String DB_DRV = "com.mysql.jdbc.Driver";
static final String DB_USER = "root";
static final String DB_PASSWD = "";

public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException,
IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {

Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;

try{
/*To connect with a database using JDBC you need to select get the
driver for the respective database and register the driver.
The forName() method of the class named Class accepts a class name
as a String parameter and loads it into the memory, Soon the is
loaded into the memory it gets registered automatically  */
//Take new instance
System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
Class.forName("com.mysql.jdbc.Driver").getDeclaredConstructor().newInstance();
connection=DriverManager.getConnection(DB_URL,DB_USER,DB_PASSWD);
statement=connection.createStatement();
resultSet=statement.executeQuery ("SELECT * FROM dept");
while(resultSet.next()){
System.out.printf("%d\t%s\t%s\n",
resultSet.getInt(1),
resultSet.getString(2),
resultSet.getString(3));
Ошибка возникает в линейке Connection = Drivermanager.getConnection (db_url, db_user, db_passwd);
Спасибо за любую помощь
Библиотека добавлена ​​


Подробнее здесь: https://stackoverflow.com/questions/642 ... -not-found

Вернуться в «JAVA»