Java 프로그램에서 모든 데이터베이스 관리 시스템에 JDBC 기반 데이터베이스 연결을 구현하려고 시도했습니다.Java 프로그램을 SQL 데이터베이스에 연결할 수 없습니다.
public class ConnectionCreate {
public connectionCreate(){
try {
//SQL Server Manager Settings
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=test","test","test");
System.out.println("Connection Established");
}catch(Exception e){
System.out.println(e);
}
}
}
내 테스트 데이터베이스는 SQL Server 관리 Studio에서 포트 1433에서 호스팅, 테스트 불렸다하고 실행중인 말했다 : 우선 내 코드는 다음과 같이보고, 마이크로 소프트 SQL Server Management Studio를 사용했습니다. 나는 등 테이블을 추가, 스튜디오 GUI를 통해 수정할 수 있지만 내 자바 코드를 호출 할 때마다이 말을 실패 : 내가가 생각할 수있는 모든 것을 확인했습니다
Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Invalid argument: connect. 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.
, jar 파일이 확실히 JDBC에 대한 발견되고있다 라이브러리에는 Class.forName 호출에 문제가 없으므로 나는 SQL Server 네트워크 구성> 프로토콜을 사용 해왔고 TCP/IP를 포함하여 모든 연결 유형을 사용할 수 있도록했습니다. 사용하는 기본 포트가 1433인지 확인했습니다. 방화벽을 설치 한 상태로 완전히 비활성화해도 작동하지 않습니다.
절망에서 벗어나 다른 데이터베이스 관리 도구를 사용해 보았습니다. PhampyAdmin 및 mysql을 사용하는 XAMPP. 다시 한번, 제대로 필요한 .JAR를 첨부 내 웹 브라우저에서 로컬로 잘 실행 보험 내 자바 테스트 스크립트에 다음 코드를 사용했습니다 :
public class ConnectionCreate {
public connectionCreate(){
try {
//MySQL Settings
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
System.out.println("Connection Established");
}catch(Exception e){
System.out.println(e);
}
}
}
이것은 또한 나에게 내 자바를 실행에 오류가 있습니다 테스트 프로그램.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
내가 여기서 무엇을해야하는지의 완전한 손실에 있어요, 내 자바 프로그램에서 어떤 작업 데이터베이스 연결을 설정할 수없는 것, 그리고 내가해야 할 수있는 다른 무엇 확실하지 않다 : 그것은 상태 내 시스템을 변경하거나 작동하도록 코드를 변경하십시오. 도움이 될 것입니다!
방금 연결하는 매우 간단한 프로그램이 복제 할 수 있습니까? 프로그램의 다른 부분에서 문제가 아닌지 확인하기 위해? 다음과 같이 테스트 할 수있는 아주 간단한 JDBC 프로그램이 있습니다. http://support.microsoft.com/kb/313100 –