public DB()

{

//JDBC설정

try {

String driverName ="org.gjt.mm.mysql.Driver"; // JDBC 드라이버에 따라 다르게 설정

Class.forName(driverName); // 드라이버이름 설정

String url = "jdbc:mysql://localhost:3306/university";

con = DriverManager.getConnection(url, "root", "1234"); //  connection 설정

stmt= con.createStatement(); //쿼리문을 실행할 statement 설정

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}// constructor

public void selectQueryOne()

{

String query="select name from instructor"; // attribute와 table이름에 따라 다르게 설정하세요.

ResultSet rs;

try {

rs = stmt.executeQuery(query); // 쿼리를 실행 시킵니다.

while(rs.next()) //쿼리 실행 결과 다수의 라인을 포함하는 경우 반복문을 통하여 결과를 가져옵니다.

{

System.out.println("hi");

System.out.println(rs.getString(1)); //쿼리의 실행 결과를 출력합니다.

}//while

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} //catch

}//selectQueryone





System.out.println("hi"); 이걸 넣은 이유는 while 문이 동작하는지 확인하기 위함인데, 전혀 동작하질 않습니다... ㅠ

에초에 rs = stmt.executeQuery(query); 이 쿼리문에서 결과값을 받아오질 않아요.. ㅠㅠㅠㅠ


Mysql과 연동되어있는데, Mysql자체에서 쿼리를 날리면 결과값이 잘 나옵니다.


혹시나 싶어 executeUpdate(query); 로 변경하여 테이블 생성쿼리를 날려봤는데, 문제 없이 생성되더군요. 


이유를 아시는분 안계신가요? ㅠㅠ