Commit 6fb35deb authored by aimarkhwang's avatar aimarkhwang

파일에 있는 멤버 정보를 DB로

parents
# Created by https://www.toptal.com/developers/gitignore/api/windows,eclipse,java
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,eclipse,java
.DS_Store
### Eclipse ###
.classpath
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
.apt_generated_test/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
# Uncomment this line if you wish to ignore the project description file.
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project
### Eclipse Patch ###
# Spring Boot Tooling
.sts4-cache/
### Java ###
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
#*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.toptal.com/developers/gitignore/api/windows,eclipse,java
\ No newline at end of file
package com.hsj.util;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class Util {
// 오늘 날짜를 가져 오는 메소드(yyyy-MM-dd)
public static String getCurrentDate(String fmt) {
SimpleDateFormat sdf = new SimpleDateFormat(fmt);
return sdf.format(new Date());
}
// 파일 읽어서 화면에 출력(파일 내용을 여기 메소드 밖으로 보내고 싶다)
public static String readLineFile(String filePath) {
BufferedReader br = null;
String retLine = "";
// StringBuffer sb = new StringBuffer();
try {
br = new BufferedReader(new FileReader(filePath));
while (true) {
String line = br.readLine();
if (line == null)
break;
retLine += line + "\n"; // 문자열을 리턴
// sb.append(line + "\n");
// System.out.println(line); // 화면에 출력
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return retLine; // sb.toString()
// return sb.toString();
}
public static ArrayList<String> readLineFileList(String filePath) {
ArrayList<String> list = new ArrayList<String>();
BufferedReader br = null;
String retLine = "";
// StringBuffer sb = new StringBuffer();
try {
br = new BufferedReader(new FileReader(filePath));
while (true) {
String line = br.readLine();
if (line == null)
break;
list.add(line);
// retLine += line + "\n"; // 문자열을 리턴
// sb.append(line + "\n");
// System.out.println(line); // 화면에 출력
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return list; // sb.toString()
}
// 파일 쓰기(새파일로 쓰기, 덮어쓰기)
public static void writeLineFile(ArrayList<String> strList, String filePath) {
PrintWriter out = null;
try {
out = new PrintWriter(filePath);
for(String s : strList) {
out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
out.close();
}
}
// 파일 쓰기(이어 쓰기)
public static void writeLineFile(ArrayList<String> strList, String filePath, boolean isAppend) {
PrintWriter out = null;
try {
out = new PrintWriter(new FileWriter(filePath, isAppend));
for(String s : strList) {
out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
out.close();
}
}
// 내가 만든 문자열을 잘라서 데이터 전달
public static void mySplit(String str, String regex1, String regex2) {
String[] strArr = str.split(regex1);
for (String s : strArr) {
// System.out.println(s);
String[] tmpArr = s.split(regex2);
// for (String ss : tmpArr) {
// System.out.println(ss);
// }
// System.out.println(tmpArr.length);
for (int i = 0; i < tmpArr.length; i++) {
if (i == tmpArr.length-1) {
System.out.print(tmpArr[i]);
} else {
System.out.print(tmpArr[i] + " / ");
}
}
System.out.println();
}
}
}
\ No newline at end of file
package dao;
import java.util.ArrayList;
import dto.MemberDto;
public interface MemberDao {
// 데이터 넣기
public void insert(MemberDto dto);
// 데이터 보기
// 데이터 한개 보기
public MemberDto selectOne(int n);
// 데이터 전체 보기
public ArrayList<MemberDto> selectAll();
// 데이터 수정
public void update(MemberDto dto);
}
package dao;
import java.sql.Connection;
import java.util.ArrayList;
import dto.MemberDto;
public class MemberDaoImpl implements MemberDao {
private Connection conn; // DB 커넥션 연결 객체
private static final String USERNAME = "root";// DBMS접속 시 아이디
private static final String PASSWORD = "1234";// DBMS접속 시 비밀번호
private static final String URL = "jdbc:mysql://localhost:3306/aidb";// DBMS접속할 db명
// 생성자에 연결
public MemberDaoImpl() {
// 디비 연결 부분
}
@Override
public void insert(MemberDto dto) {
// TODO Auto-generated method stub
}
@Override
public MemberDto selectOne(int n) {
// TODO Auto-generated method stub
return null;
}
@Override
public ArrayList<MemberDto> selectAll() {
// TODO Auto-generated method stub
return null;
}
@Override
public void update(MemberDto dto) {
// TODO Auto-generated method stub
}
}
package dto;
public class MemberDto {
// 번호
private int num;
// 이름
private String name;
// 전공
private String major;
// 이메일
private String email;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
package member;
import java.util.ArrayList;
import com.hsj.util.Util;
import dto.MemberDto;
public class MainClass {
public static void main(String[] args) {
// 멤버 정보 DB 활용
// 파일에 있는 데이터를 읽어오기
String filePath = "C:/dev/file/전공정보.txt";
Member member = new Member();
ArrayList<MemberDto> list = member.getMemberList(filePath);
for (MemberDto d : list) {
System.out.println(d.getName());
}
// System.out.println("쉼표로 구분되는 데이터 갯수: " + spData.length);
// 읽어온 데이터를 DB에 넣기
// 데이터 보기
// 데이터 수정
}
}
package member;
import java.util.ArrayList;
import com.hsj.util.Util;
import dto.MemberDto;
public class Member {
public ArrayList<MemberDto> getMemberList(String filePath) {
ArrayList<MemberDto> retList = new ArrayList<MemberDto>();
ArrayList<String> spList = Util.readLineFileList(filePath);
for (String s : spList) {
MemberDto dto = new MemberDto();
String[] sp = s.split(",");
dto.setNum(Integer.parseInt(sp[0])); // 문자열을 숫자로
dto.setName(sp[1]);
dto.setMajor(sp[2]);
dto.setEmail(sp[3]);
retList.add(dto);
}
return retList;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment