import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;

public class LoadToCsv {
public static void main(String[] args) {
String csvPipeDivide = "\\|"; // 구분자
try {
File csvFile = new File("C:\\Users\\king\\Desktop\\shapeFile\\a.csv");
BufferedReader br = new BufferedReader((new FileReader(csvFile)));
int count = 0;
String line = null;
while((line=br.readLine())!=null) {
count = count+1;
String[] value = line.split(csvPipeDivide);
System.out.println(Arrays.toString(value));
}
//System.out.println(count);
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Posted by kingroad

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;

public class App {

public static void main(String[] args) throws IOException {
String anotherInputFilePath = "C:\\Users\\king\\Desktop\\shapeFile\\a.shp";
String anotherOutputFilePath = "C:\\Users\\king\\Desktop\\shapeFile\\a.csv";

BufferedWriter bw = new BufferedWriter(new FileWriter(anotherOutputFilePath));

loadToShp loadShape = new loadToShp();
loadShape.DefaultLoad(anotherInputFilePath);
StringBuffer tmpStr = new StringBuffer();

List properties = (List) loadShape.getIter().next().getProperties();
// 프로퍼티 명
for (int i = 0; i < properties.size(); i++) {
if(i==(properties.size()-1)) {
tmpStr.append(properties.get(i).getName()).append("\n");
} else {
tmpStr.append(properties.get(i).getName()).append("|");
}
//tmpStr.append("\n");
//System.out.printf("%d번째 진행중",i);
}
bw.write(tmpStr.toString());
// 프로퍼티 명 쓰기 End

 

// 레코드를 파일에 쓰기
int x=0;

//파일이 너무 커서 레코드의 갯수를 저장하기용 또는 레코드가 잘 써지는지 10만줄에 따라 print해보기용

while(loadShape.getIter().hasNext()) {
if((x%100000)==0) {
System.out.println(tmpStr.toString());
}

//if(x==10){

//bw.close(); 
//break; }


tmpStr = new StringBuffer();
SimpleFeature f = loadShape.getIter().next();

for(int i=0; i<f.getAttributeCount(); i++) {
if(i==(f.getAttributeCount()-1)) {
tmpStr.append(f.getAttribute(i).toString()).append("\n");
} else {
tmpStr.append(f.getAttribute(i).toString()).append("|");
}
}
//System.out.println(tmpStr.toString());
bw.write(tmpStr.toString());
x++;

}
bw.close();
}
}

 

// csv file이 잘 써졋는지 확인을 하기 위해서 excel로 csv파일을 열었을 때 변환하려는 원본 파일이 너무 크다면

// 파일 용량은 증가했으나 백지로 열리는 경우가 있는데

// excel->데이터 항목->데이터 가져오기->파일에서->텍스트/csv->저장된 excel 파일 클릭->구분기호 지정 ex) | 또는 ,

// ->로드 순으로 열어서 확인해볼 수 있다

// 또한 데이터가 일치하지 않아 보일 수 있는데 excel의 문제이다. 파일 레코드를 소량만 변환하여 notepad++와 같은 // 다른 도구를 사용하여 확인을 해보면 정상적으로 변환됨을 확인할 수 있다. 

Posted by kingroad

import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;


public class loadToShp {
private static SimpleFeatureIterator simpleFeatureIterator;

public void DefaultLoad(String filePath) {
// Open the shapefile
File dataFile = new File(filePath);

ShapefileDataStore store;

try {
store = new ShapefileDataStore(new URL("file://" + dataFile));
store.setCharset(Charset.forName("UTF-8"));
SimpleFeatureSource source = store.getFeatureSource(store.getTypeNames()[0]); 

//file의 이름을 인자로 하여 그 이름에 해당된 정보를 가지고 옴
SimpleFeatureCollection featureCollection = source.getFeatures();
simpleFeatureIterator = featureCollection.features();

} catch (IOException e) {
e.printStackTrace();
}
}

public SimpleFeatureIterator getIter() {
return simpleFeatureIterator;
}
}

Posted by kingroad

int[] score = new int[]{50, 60, 70, 80, 90};

int[] socre = {50, 60, 70, 80, 90}; //new int[]를 생략 가능함.

 

int[] score;

score = new int[]{50, 60, 70, 80, 90}; // OK

score = {50, 60, 70, 80, 90}; // error -> new int[] 생략 불가

 

배열을 간단히 출력하는 방법으로는

System.out.println(Arrays.toString(score)); 와 같이 출력하면 된다

만약에 System.out.println(score); 처럼 출력을 하려고 시도하였다면 배열의 주소가 출력되었을 것이다.

다만 예외적으로 char 배열은 println메서드로 출력하면 각 요소가 구분자 없이 그대로 출력된다

 

char[] chArr = {'a', 'b', 'c', 'd'};

System.out.println(chArr); // abcd가 출력된다

마찬가지로 배열로 출력하려면 

System.out.println(Arrays.toString(chArr));를 사용하면 된다.,

Posted by kingroad

 

Posted by kingroad

- apt-get을 이용하여 Oracle JDK Install

$ sudo add-apt-repository ppa:webupd8team/java

$ sudo apt-get update

$ sudo apt-get install oracle-java8-installer

- version 확인

$ java -version

java version "1.8.0_181"

Java(TM) SE Runtime Environment (build 1.8.0_181-b13)

Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

 

Posted by kingroad

지난번에 한 기초 별찍기 1과 별 차이가 없다.

첫 번째 for문 안에서 별의 앞에 찍어줄 공백을 먼저 찍어주는 for문을 돌린다음에

실제로 별을 찍을 세 번째 for문에서 별을 찍어주면 된다.

2*i를 하는 이유는 피라미드형으로 찍기 위해 앞 뒤로 별을 찍어주기 위함이며 +1을 한 이유 역시 가운데에 별을 찍기 위함이다.

Posted by kingroad

Posted by kingroad

솔직히 별거 없다.

중요한 것은 environments안에 있는 프로퍼티 정보들로 디비에 연결을 시킨다는 것이고

실제 쿼리를 날리는 mapper의 위치를 지정해주면 된다.

typeAliases는 말 그대로 리눅스등 여러 환경설정에서 사용해주는 Aliase와 역할이 같다.

Mapper에서 return을 시켜줄 때 DTO나 Vo로 리턴을 시킨다고 할 때 returnType을 풀패키지명+DTO(VO)이름으로 적을 필요 없이 alias명만 적어주어 편하게 사용하기 위함이다.

'프로그래밍 > MyBatis' 카테고리의 다른 글

DAO & Mapper  (0) 2018.07.21
Posted by kingroad

2019. 11. 12. 14:55 프로그래밍/Jdbc

Postgre JDBC

jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/DB명
jdbc.username=********
jdbc.password=********

Posted by kingroad
이전버튼 1 2 3 4 이전버튼

블로그 이미지
개발자를 꿈꾸는 코린이 입니다
kingroad

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.5
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

최근에 올라온 글

최근에 달린 댓글

글 보관함