Zer0
22
2019-08-05 13:44:17 작성 2019-08-05 14:01:45 수정됨
5
144

JSP/Servlet DB연결 질문입니다!! 부디 한번만 봐주세요!!


질문을 드리기 전에 3~4일 정도 계속해서 구글링도 해보고 찾아보고는 했는데 아직 찾는 실력이 부족한지 잘 못 찾았습니다 


아래는 src/pack/MariaConn 이고, 정상적으로 연결 됨을 확인했습니다.


package pack;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MariaConn {

public static void main(String[] args) {
Connection con = null;

String server = "localhost"; // 서버 주소
String database = ""; // DATABASE
String user_name = "";
String password = "";

// 1.드라이버 로딩
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.err.println(" !! <JDBC 오류> Driver load 오류: " + e.getMessage());
e.printStackTrace();
}

// 2.연결
try {
con = DriverManager.getConnection("jdbc:mysql://" + server + "/" + database + "?useSSL=false", user_name, password);
System.out.println("정상적으로 연결되었습니다.");
} catch(SQLException e) {
System.err.println("con 오류:" + e.getMessage());
e.printStackTrace();
}

// 3.해제
try {
if(con != null)
con.close();
} catch (SQLException e) {}
}


}




그러나 DAO를 만들어서(src/pack/Notice_Board_DAO)JSP에서 뺄려고 하면 계속 Driver 오류가 발생하는데(DTO도 만들어 뒀습니다!!)

package pack;

import java.sql.*;
import java.util.ArrayList;

public class Notice_Board_DAO {
private String server = "localhost"; // 서버 주소
private String database = ""; // DATABASE 이름
private String user_name = ""; // 서버 아이디
private String password = ""; // 서버 비밀번호


public Notice_Board_DAO(){
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.err.println(" !! <JDBC 오류> Driver load 오류: " + e.getMessage());
e.printStackTrace();
}
}

public ArrayList<Notice_Board_DTO> Notice_Board_Select(){

ArrayList<Notice_Board_DTO> dtos = new ArrayList<Notice_Board_DTO>();

Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try {
con = DriverManager.getConnection("jdbc:mysql://" + server + "/" + database + "?useSSL=false", user_name, password);
stmt = con.createStatement();
rs = stmt.executeQuery("select * from register");
System.out.println("정상적으로 연결되었습니다.");

while(rs.next()){
String id = rs.getString("id");
String pw = rs.getString("pw");
//int Num = rs.getInt("num");
//String title = rs.getString("title");
//String contents = rs.getString("contents");
//String date = rs.getString("date");

Notice_Board_DTO dto = new Notice_Board_DTO(id, pw, 0, null, null, null);
dtos.add(dto);
}

} catch(SQLException e) {
System.err.println("con 오류:" + e.getMessage());
e.printStackTrace();
} finally {
try{
if(rs != null) rs.close();
if(stmt != null) stmt.close();
if(con != null) con.close();
}catch (Exception e){
e.printStackTrace();
}
}

return dtos;
}


}

아래는 JSP 입니다.


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="pack.Notice_Board_DAO" %>
<%@ page import="pack.Notice_Board_DTO" %>
<%@ page import="java.util.ArrayList" %>
<html>
<head>
<title>ZeroLab</title>
</head>
<body>
<div class = "login">
<%

Notice_Board_DAO noticeDAO = new Notice_Board_DAO();
ArrayList<Notice_Board_DTO> dtos = noticeDAO.Notice_Board_Select();

for(int i=0; i <dtos.size(); i++){
Notice_Board_DTO dto = dtos.get(i);
out.println(dto.getID());
out.println(dto.getPW());
}

%>
</div>
</body>
</html>


이렇게 구성을 하면,


java.lang.ClassNotFoundException: org.mariadb.jdbc.Driver

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1955)

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1798)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:264)

at pack.Notice_Board_DAO.<init>(Notice_Board_DAO.java:15)

at org.apache.jsp.login_jsp._jspService(login_jsp.java:103)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:472)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:319)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:748)


java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/mydb?useSSL=false

at java.sql.DriverManager.getConnection(DriverManager.java:689)

at java.sql.DriverManager.getConnection(DriverManager.java:247)

at pack.Notice_Board_DAO.Notice_Board_Select(Notice_Board_DAO.java:31)

at org.apache.jsp.login_jsp._jspService(login_jsp.java:104)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:472)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:319)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:748)


오류가 출력됩니다 ㅠㅠ... 

혹시나 조언을 구할 수 있으면 감사하겠습니다!!


0
0