khac phuc mot so loi thuong gap tren java khi ket noi csdl – Tài liệu text

khac phuc mot so loi thuong gap tren java khi ket noi csdl

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (32.95 KB, 13 trang )

Khi kết nối Java đến SQL Server sẽ có thể gặp phải một số lỗi:
– java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver: Chưa build
path thư viện

– Java Runtime Environment (JRE) version 1.8 is not supported by this driver. Use the sqljdbc4.jar
class library, which provides support for JDBC 4.0.: thêm nhầm thư viện sqljdbc.jar. Phải thêm file
sqljdbc4.jar, sqljdbc41.jar, sqljdbc42.jar,…

– com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost1, port
1433 has failed. Error: “connect timed out. Verify the connection properties. Make sure that an instance
of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP
connections to the port are not blocked by a firewall.”.

Lỗi này có thể do rất nhiều nguyên nhân:
+ Sai url localhost
+ Sai port (mặc định 1433), hoặc không biết được port đã config trên Server: Vào “SQL
Server Configuration Manager” > “SQL Server Network Configuration” > “Protocols for MSSQLSERVER” >
“TCP/IP” > “IP Addresses” > “IPAll” để xem port đã config

Hoặc có thể port mặc định đã bị tường lửa chặn không cho hoạt động. Để thiết lập lại
tường lửa: “Windows + R” > “WF.msc” > “Inbound Rules” > “Add Rules” (theo hướng dẫn tại đây:
/>
+ TCP/IP Protocol trong SQL Server Network Configuration chưa được Enable. Vào “SQL
Server Configuration Manager” > “SQL Server Network Configuration” > “Protocols for MSSQLSERVER” >
“TCP/IP” > Enable

– com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database “NgocKhuong”
requested by the login. The login failed.
Không tìm thấy database đã config trên server (Ví dụ ở đây là NgocKhuong)

– Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated
authentication:
Từ phiên bản sqljdbc_6.0 thì phải cần thêm thư viện sqljdbc_auth để mới có thể kết nối đến sql
server bằng phương thức xác nhận không cần username & password server. Để kết nối, cần copy file
sqljdbc_auth.dll vào thư mục C:\Windows\System32

Hoặc có thể set java path cho thư viện đó như sau:
-Djava.library.path=C:\bla\path\where\the\dll\is
Ví dụ:
“-Djava.library.path=C:\Program Files (x86)\jdbc\sqljdbc_4.0\enu\auth\x86”

Hoặc có thể port mặc định đã bị tường lửa chặn không cho hoạt động. Để thiết lập lạitường lửa: “Windows + R” > “WF.msc” > “Inbound Rules” > “Add Rules” (theo hướng dẫn tại đây:/>+ TCP/IP Protocol trong SQL Server Network Configuration chưa được Enable. Vào “SQLServer Configuration Manager” > “SQL Server Network Configuration” > “Protocols for MSSQLSERVER” >”TCP/IP” > Enable- com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database “NgocKhuong”requested by the login. The login failed.Không tìm thấy database đã config trên server (Ví dụ ở đây là NgocKhuong)- Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.pathcom.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integratedauthentication:Từ phiên bản sqljdbc_6.0 thì phải cần thêm thư viện sqljdbc_auth để mới có thể kết nối đến sqlserver bằng phương thức xác nhận không cần username & password server. Để kết nối, cần copy filesqljdbc_auth.dll vào thư mục C:\Windows\System32Hoặc có thể set java path cho thư viện đó như sau:-Djava.library.path=C:\bla\path\where\the\dll\isVí dụ:”-Djava.library.path=C:\Program Files (x86)\jdbc\sqljdbc_4.0\enu\auth\x86″