import java.io.*;
import java.sql.*;
import java.util.Date;

public class UpdateItem
{
	public UpdateItem()
	{
	}

	public void loadDriver() throws ClassNotFoundException, Exception
	{
  		Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
	}

	public boolean update(int num, String email, String title, String content, String password, String remoteAddr) throws SQLException
	{
       		String url="jdbc:oracle:thin:@localhost:1521:etri";
        		Connection con;
       		Statement stmt;
       		boolean isNormalExit = false;

 	   	con = DriverManager.getConnection(url, "scott", "tiger");
	   	stmt = con.createStatement();

	   	String query = "update board set BDATE = SYSDATE, BEMAIL = '" + email +
	                                                    "',   BTITLE = '" + toHangul(title) +
	                                                    "',  BCONTENT = '" + toHangul(content) +
	                                                    "',BPASSWORD = '" + password +
	                                                    "' where bnum = " + num;
     		//  getRemoteAddr을 사용하여 글 작성자의  IP를 확인합니다.

	   	int rowChange = stmt.executeUpdate(query);

	   	if(rowChange == 1)
       			isNormalExit = true;
     		else
      			isNormalExit = false;

	   	stmt.close();
	   	con.close();

	   	return isNormalExit;
	}

   	// 데이타베이스에 쓸때
   	private String toHangul(String str)
   	{
      		if (str == null)
             		return null;
      		try
      		{
         		return new String(str.getBytes("8859_1"), "KSC5601");
      		}
      		catch (UnsupportedEncodingException e)
      		{
      		}
      		return null;
   	}

	//한글을 데이터베이스의 유니코드로 변환
   	private String hangulTo(String str)
   	{
      		if (str == null)
            		return null;
      		try
      		{
            		return new String(str.getBytes("KSC5601"), "8859_1");
      		}
      		catch (UnsupportedEncodingException e)
      		{
      		}
      		return null;
   	}
}
