반응형
JSF를 사용하여 연결 빈의 데이터베이스 (MYSQL)에 연결하여 콘텐츠를 검색하려면 어떻게해야합니까? 또한 web.xml 파일을 구성하는 방법을 알려주십시오.
해결 방법
mysql에 연결하려면 :
public void open() {
try {
String databaseName = "custom";
String userName = "root";
String password = "welcome";
//
String url = "jdbc:mysql://localhost/" + databaseName;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(url, userName, password);
} catch (Exception e) {
System.out.println("Not able to connect");
}
}
이 경우 web.xml에는 변경할 사항이 없지만 pom.xml에 추가하면됩니다.
<dependency>
<groupId>groupId = mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
이것은 성공적으로 작동했습니다.
참조 페이지 https://stackoverflow.com/questions/319936
반응형
'MySql' 카테고리의 다른 글
MySQL Echo current number of row (0) | 2020.11.19 |
---|---|
MySQL 라 라벨에서 DB :: select 내에서 DB :: raw를 사용하는 이유는 무엇입니까? (0) | 2020.11.18 |
MySQL 다른 열에서 동일한 테이블을 두 번 조인 (0) | 2020.11.18 |
MySQL Windows 10으로 업그레이드하면 MySQL 워크 벤치가 중단됩니까? (0) | 2020.11.18 |
MySQL 여러 데이터베이스에 부여합니다. MySQL (0) | 2020.11.18 |
댓글