http://programmingskills.net/archives/542 를 참고하여 해결했습니다.
데이터베이스 책을 따라 예제를 진행하다가 이런 오류가 떴다.
검색해보았더니 코드에 한글이 들어가 있었던 것이 문제였던 것 같다.
책을 따라 작성했던 코드는 다음과 같다.
import java.io.*;
import java.sql.*;
public class showMember{
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=bookstore;";
String user = "big";
String password = "difka03196!!";
String query = "SELCET 회원번호,회원명,등급,주소 FROM 회원";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn=DriverManager.getConnection(url,user,password);
}catch(SQLException e) {
e.printStackTrace();
}
try {
stmt=conn.createStatement();
rs=stmt.executeQuery(query);
System.out.println(" 회원번호 \t회원명 \t\t등급 \t\t주소 ");
while(rs.next()) {
System.out.print("\t"+rs.getInt("회원번호"));
System.out.print("\t"+rs.getString("회원명"));
System.out.print("\t"+rs.getString("등급"));
System.out.print("\t"+rs.getString("주소"));
}
if(rs != null) rs.close();
if(stmt != null) stmt.close();
if(conn != null) conn.close();
}catch(SQLException e) {
e.printStackTrace();
}
}
}
그래서
javac showMember.java
에서
javac showMember.java -encoding UTF8
-encoding UTF8을 추가해주었더니
컴파일이 정상적으로 이루어졌다.
간단하게 해결!
'etc.' 카테고리의 다른 글
Moonlight 앱으로 데스크탑과 태블릿 원격 연결하기 (0) | 2022.05.16 |
---|---|
윈도우 10 환경 변수(시스템 변수) Path 복원 과정 (1) | 2020.08.05 |