◽ JSP

MySQL 연동 - JDBC

DB 접속


1
2
3
4
5
6
7
8
9
10
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 
<%
//디비접속
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/test?serverTimezone=UTC";
String user="root";
String password="1111";
%>
r

 

 

DB 목록 출력하기.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
     <%
    String sql = "";
    sql = "select * from notice where gongji != 1 order by uid desc limit 3, 4";
        
    Connection conn = DriverManager.getConnection(url, user, password);
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
                    
    while (rs.next()) {
        String subject = rs.getString("subject");
                            
    %>
        <tr>
            <td width=10></td>
            <td colspan=3 height=20><%=subject%></a></td>
            <td width=10></td>
        </tr>
                          
    <%}%>
r

subject라는 값들이 출력이 된다.

푸터바