HTTP Servlet 프로그램에서 SQL Server 데이터베이스를 사용하고 싶지만 프로그램이 데이터베이스에 연결할 수없는 것 같습니다. 다음과 같은 오류가 발생합니다.
jdbc : sqlserver : // localhost : 1433; databaseName = Bookyard; integratedSecurity = true;에 적합한 드라이버가 없습니다.
이것이 내 연결 방법입니다.
package practice.bookyard.server.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Database {
public static Connection getConnection() {
String url = "jdbc:sqlserver://(LocalDb)\\MSSQLLocalDB:1433;databaseName=Bookyard;integratedSecurity=true;";
Connection connection = null;
try {
connection = DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
}
localhost:1433
이전 과 같이 서버 이름이 있었지만 SQL Server 인스턴스 이름으로 변경 (LocalDb)\\MSSQLLocalDB:1433
했지만 여전히 이전 이름을 선택하는 것 같습니다.
또한 SQL Server localdb에 연결할 때 올바른 연결 문자열을 제공하는 방법을 모르겠습니다.
Java EE, Mars 2 용 Eclipse를 사용하고 있으며이 웹 사이트 에서 SQL 6.0 용 Microsoft JDBC 드라이버를 다운로드했습니다 .
설치를 실행하고 결과 폴더의 내용을 압축 해제했습니다. 그런 다음 JDK 1.8을 대상으로 할 때 빌드 경로에 sqljdbc42.jar 파일을 추가했습니다 .
최신 정보
Scary Wombat의 제안에 따라 sqljdbc42.jar 파일 의 경로도 내 클래스 경로에 추가했습니다 .
그러나 여전히 동일한 오류가 발생합니다.
유형 로더가 내 연결 문자열에서 드라이버 유형을 해결할 수 없다는 점에서 이것이 반영 문제라고 확신합니다. 즉, 사용중인 연결 문자열 구문이 잘못되었습니다.
연결 문자열을 다음과 같이 변경했습니다.
String url = "jdbc:sqlserver://localhost:1433;
instance=(LocalDb)\\MSSQLLocalDB;
databaseName=Bookyard;integratedSecurity=true;";
However, I still not only get the same error but the exception message I receive still has my old connection string. So, clearly, there's also some caching going on, I just don't know where. Who is caching my connection string and how do I refresh / clear that cache?
Could you please tell me how to provide a SQL Server instance name if I am connecting to localdb and not on the main SQL Server instance?
As @ScaryWombat and @JozefChocholacek had hinted, it turned out to be a class path issue. Apparently, you have to copy and paste just the sqljdbc42.jar file, and this file only directly into the WEB-INF\lib
folder and not within any sub-folder.
I did that it still gave me that error.
WEB-INF
에서 볼 때 폴더 구조가 Project Explorer
여전히 이전 폴더 구조를 가지고 있기 때문 입니다. 그래서의 WEB-INF
폴더를 마우스 오른쪽 버튼으로 클릭 Project Explorer
하고 Refresh
명령을 선택했습니다 .
또한 폴더 CLASSPATH
를 가리 키도록 환경 변수 를 업데이트 WEB-INF
했는데 그 오류가 사라졌습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다