JDBC 데이터베이스 조회

1155 단어 자바
package org.lxh.execdemon;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


//         
public class ResultSetDemon01 {

	public static final String DBDRIVER = "oracle.jdbc.driver.OralceDriver";
	
	public static final String DBURL = "jdbc:oracle:thin:@locast:1521:orcl";
	
	public static final String DBUSER = "admin";
	
	public static final String DBPASS = "admin";
	
	public static void main(String[] args) throws Exception{
		
		Connection conn = null;//           
		
		Statement stmt = null;//         
		
		ResultSet result = null;//             
		
		Class.forName(DBDRIVER);//  class       
		
		conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);//     
		
		stmt = conn.createStatement();//tatement      connection         
		
		result = stmt.executeQuery("select * from person");//  sql  ,     result 
		
		while(result.next()){//         
			String name = result.getString("name");//     person  name    
			System.out.println(name);
		}
		result.close();
		stmt.close();
		conn.close();
		
	}

}

좋은 웹페이지 즐겨찾기