2011-09-04 6 views
1

Java로 MySQL 데이터베이스에 연결하고 싶습니다.Java 데이터베이스로 연결

JDBC를 사용하고 있는데 드라이버가 설치되어 있습니다.

Class.forName("com.mysql.jdbc.Driver"); 
Connection connection = DriverManager.getConnection("jdbc:mysql:/mydomain.com/mydatabase", "username", "password"); 

내가 작성하는 방법을 긍정적 아니다 : 여기

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException The last packet sent successfully to the server was 0 milliseconds ago.

내 코드입니다 : (com.mysql.jdbc.Driver는)

유일한 문제는 내가 오류가 점점 계속 것입니다 URL (그리고 어디에서 내 사용자 이름과 암호를 얻을 수 있습니까?) 그러나 나는 많은 연구를 해왔습니다.

저는 데이터베이스와 도메인에 접근 할 수있는 유일한 사람이므로 관리자에게 묻는 데는 아무런 도움이되지 않습니다.

저는 phpMyAdmin을 사용하여 데이터베이스를 만들고 관리합니다. 내 phpMyAdmin 사용자 이름과 암호 또는 무엇을 사용합니까?

그런데 내 사이트는 야후! 중소 기업.

그래서 제 질문은 다음과 같습니다

  • 어떻게 연결 URL을해야합니까?
  • 내 사용자 이름 및 암호 란 무엇입니까?
+1

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html –

+0

이 질문은 결국 대답 했습니까? – speedRS

+0

[MySQL과의 Java 연결성] (MySQL의 연결성) (http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql) – Nekto

답변

0

How do I make the connection URL?

당신은 당신의 URL에 슬래시를 누락? 나는 그것이 다음과 같을 것이라고 가정했을 것이다.

jdbc:mysql://server/database 
1

나는 당신의 URL에 슬래시가 없다고 말할 것이다.

Connection connection = DriverManager.getConnection("jdbc:mysql://mydomain.com/mydatabase", "username", "password"); 

또는 귀하의 액세스 권한에 문제가 있다고 생각됩니다. 이것도 똑같은 일이 나에게 일어 났으며 방화벽이 서버의 포트를 차단하는 문제였습니다. 그래서 이것이 사실이 아닌지 확인하십시오.

0
Load the drivers for mysql 
Class.forName("com.mysql.jdbc.Driver"); 
connect with the data base 
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/widget_corp","dbuser","dbpassword");    
.....jdbc:mysql://this is use as it is 
.....127.0.0.1 this is the address of localhost You can use the word "localhost" insted of  "127.0.0.1" 
.....dbuser is the data base user 
.....dbpassword is the password of the dbuser 
.....3306 is the default port used for database