유형 4 연결의 jdbc를 사용하여 데이터베이스에 연결하는 프로그램을 작성했습니다. 프로그램은 정상적으로 컴파일되지만 java.lang.ClassNotFoundException : com.mysql.jdbc.Driver의 예외를 제공합니다. 내 자바 파일이있는 폴더에있는 모든 폴더의 압축을 푼 다음 모든 jar 파일과 데이터베이스를 같은 폴더에 저장했습니다. 데이터베이스에는 ID가 1과 2 인 두 개의 레코드가 들어 있습니다.mysql을 사용한 JDBC 유형 4 연결
import java.sql.*;
class TestJDBC {
public static void main(String aa[]) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Student_Details", "root","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select ID, studentname from Details where ID=1");
while(rs.next()) {
System.out.print(rs.getString("ID"));
System.out.print("\t");
System.out.println(rs.getString("StudentName"));
}
}
catch(Exception e) {
System.out.println(e);
}
}
}
그것을 시도하지만 당신이 IDE를 사용하고 여전히 같은 예외 –
를 받고 사용 중복 항아리를 가지고 있겠지 확인 또한
실행? – BevynQ
아니요 명령 줄 사용 –