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

import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class SelectMaxNum implements SessionBean 
{
	
	public SelectMaxNum()
	{
	}

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


	public int getMaxNum() throws SQLException
	{
       		String url="jdbc:oracle:thin:@129.254.75.152:1521:orcl816";
        	Connection con;
       		Statement stmt;


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

   		String CountQuery = "select max(BNUM) as rc from board ";
   		ResultSet rc = stmt.executeQuery(CountQuery);
   		rc.next();

   		int num  = rc.getInt("rc") + 1;


   		stmt.close();
   		con.close();
   		
   		return num;
   	}

   	// 데이타베이스에 쓸때
   	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;
   	}
}
