내가 팔로우 한 사람 목록 확인
개발 환경
Table의 필드는 one two가 존재하고, one는 팔로우 한사람 two는 팔로우 받는사람을 기준으로 작성.
최대팔로우 수는 100명을 기준으로 작성. (코드내에서 DEFINE으로 적용가능)
Index.jsp
내 팔로우목록 <br>
<%
Friendlist f = new Friendlist();
String[] followlist = f.list(id);
int i=0;
while (true){
if(followlist[i] == null) {break;}
%>
<%= followlist[i]%> <br>
<%
i++;
}
%>
Friendlist.class (내 팔로우 목록)
package example;
import java.sql.*;
public class Friendlist {
public String[] list(String id)
{
String dbid = "DBID";
String dbpw = "DBPW";
String dbname = "DBNAME";
String tablename = "TABLENAME";
String[] list = new String[100];
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+dbname+"?useUnicode=true&characterEncoding=utf-8", "alpacao", "alpaca16");
String sql = "select * from "+tablename +" where one='" + id + "'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int i =0;
while(rs.next())
{
list[i] = rs.getString("two");
if(list[i] == null) return list;
i++;
}
}catch(Exception e) {
}
return list;
}
}
Follower.class (위 Followlist.class와 동작방식은 같으나 SQL 문법과 필드 불러오는부분만 변경.)
package example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Follower {
public String[] list(String id)
{
String dbid = "DBID";
String dbpw = "DBPW";
String dbname = "DBNAME";
String tablename = "TABLENAME";
String[] list = new String[100];
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+dbname+"?useUnicode=true&characterEncoding=utf-8", "alpacao", "alpaca16");
String sql = "select * from "+tablename +" where two='" + id + "'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int i =0;
while(rs.next())
{
list[i] = rs.getString("one");
if(list[i] == null) return list;
i++;
}
}catch(Exception e) {
}
return list;
}
}
'JAVA JSP' 카테고리의 다른 글
[JSP] 로그인 구현 (0) | 2020.04.12 |
---|---|
[JSP] SHA-256인코딩 (0) | 2020.04.10 |
[IntelliJ] .war배포파일 만들기 (0) | 2020.04.07 |
[JSP] 로그아웃처리 (0) | 2020.04.07 |
[JSP] 내가 만든 Class import하기 (0) | 2020.04.07 |
최근댓글