'Java'에 해당되는 글 3건

  1. 2008.11.25 JAVA 문자열 자르기
  2. 2008.11.05 java int,String형 변환
  3. 2008.11.05 java,mysql,tomcat,eclipse 환경
posted by 준치 2008. 11. 25. 01:13
class StringSplit3
{
      public static void main(String[] args)
      {
            String str = "1,김천재,100,100,100,`2,박수재,95,80,90,`3,이자바,80,90,90,`4,소주섭,70,60,90,";

            String[] data = str.split("`");             // `를 구분자로 해서 문자열을 나눈다.
            String[] subData=null; 
            Student[] score = new Student[data.length];

            for(int i=0;i < data.length;i++) {
                  subData = data[i].split(",");       // , 를 구분자로 해서 문자열을 나눈다.
                  score[i] = new Student(subData[0],subData[1],subData[2],subData[3],subData[4]);
            }

            for(int i=0;i < score.length;i++) {
//                   System.out.println(score[i].toString()); 이문장과 아래문장은 같은 결과를 얻는다.
                  System.out.println(score[i]);
            }
      }
}

class Student
{
      String no="";
      String name="";
      String korean="";
      String english="";
      String math="";

      Student(String no, String name, String korean, String english, String math) {
            this.no = no;            
            this.name = name;            
            this.korean = korean;            
            this.english = english;            
            this.math = math;            
      }

      public String toString() {
            return "번호:" + no + ", 이름:" + name + ", 국어:" + korean + ", 영어:" + english + ", 수학:"+ math;
      }

}

/*
번호:1, 이름:김천재, 국어:100, 영어:100, 수학:100
번호:2, 이름:박수재, 국어:95, 영어:80, 수학:90
번호:3, 이름:이자바, 국어:80, 영어:90, 수학:90
번호:4, 이름:소주섭, 국어:70, 영어:60, 수학:90
*/

정보보안  민호쌤? 거기서 퍼옴 C#이랑 다를게 역시..없군.....
posted by 준치 2008. 11. 5. 21:29
tring은 int형으로, int형은 String으로

ParseExam.java

Java에서의 형 변환은 빈번히 일어나는 일이다.
그래서 형 변환에 관해서는 필수적으로 알아야 한다.
그 중 가장 많이 일어나는 String->int, int->String에 대해서 살펴보자.
String을 int형으로 바꾸기 위해서는 java.lang팩키지의 Integer클래스에서 parseInt(String s)메소드를 알아야 한다.
public static int parseInt(String s) throws NumberFormatException
매개변수로 String클래스의 인스턴스 s를 받아서 숫자로 변환이 가능하면 int형의 값을 반환한다.
만약에 숫자로 변환이 가능하지 않으면 NumberFormatException이라는 RuntimeException을 던지는 메소드이다.
두번째는 int형을 String으로 바꾸는 과정이다. 이것은 java.lang팩키지의 String클래스에서 valueOf(int i)메소드를 알아야한다.
public static String valueOf(int i)
매개변수 int형의 변수 i를 받아서 String형의 인스턴스를 반환한다.
Integer.toString()에 의해서 반환되는 값과 동일하다.
위의 두 메소드만 알면 String과 int형 사이에서의 형 변환은 쉽게 할 수 있다.
public class ParseExam {

public static void main(String[] args) {

String numStr = "54";

// String값을 int형의 값으로 바꾸는 방법
int numInt = Integer.parseInt(numStr);
System.out.println(numInt);

// int형의 값을 String으로 바꾸는 방법
String numStr2 = String.valueOf(numInt);
System.out.println(numStr2);
}

}
posted by 준치 2008. 11. 5. 21:28

버젼따라 다르겠지만 우선 올라와있길래 가져왔습니다...ㅎㅎㅎ
설치과정

1. 자바
    1. http://www.sun.com-> download-> java SE-> jdk 6 update 5
    2. 설치..
    3. 내컴퓨터 -> 오른쪽 마우스 등록정보 -> 고급 -> 환경변수 ->
        path-> C:\Program Files\Java\jdk1.6.0_05\bin; 추가

2. Tomcat
    1. http://www.apache.org-> download-> Tomcat-> Tomcat5.5-> core: Windows Service Installer
    2. port: 8080, userName: user, Password: passwd
    3. 마지막 부분에 체크해제후 finish.

3. eclipse
    1. http://www.eclipse.org/download-> 오른쪽에서 Web Tool-> 2.0.1->
        Web Tools Platform All_in_One Package
    2. c:에 압축풀기

4. MySQL
    1. http://www.sun.com-> download-> MySQL
    2. 설치옵션중 ManualSetting: 200
                  Manul Selected...
                  Include... 체크하기

5. Tomcat 실행

6. Oracle
    1. http://www.oracle.com
    2. 암호: passwd, port: 8081
        tip) 포트번호가 틀렸을때 수정하기!
            SQL콘솔에서
                1. connect system/passwd;
                2. exec dbms_xdb.sethttpport(8081);
                3. C:\oraclexe\app\oracle\product\10.2.0\server\Database_homepage.html에서
                    오른쪽클릭-> 등록정보-> 주소명을 8080에서 8081로 변경

7. Tomcat Plugin
    1. http://www.eclipsetotale.com/tomcatPlugin.html-> PluginV321.zip 다운받기
    2. C:\eclipse\plugins에 압축풀기
        tip) plugin을 나중에 설치했을때
            1. 실행창에서 C:\eclipse\eclipse.exe -clean

8. DB설정(JDBC)
    1. C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar파일을
        C:\Program Files\Java\jre1.6.0_05\lib\ext 또는
        C:\Program Files\Java\jdk1.6.0_05\jre\lib\ext에 복사하기
    2. http://dev.mysql.com/downloads-> Connectors-> Connector/J->
        mysql-connector-java-5.1.6.zip-> mysql-connector-java-5.1.6-bin.jar파일을
        C:\Program Files\Java\jre1.6.0_05\lib\ext 또는
        C:\Program Files\Java\jdk1.6.0_05\jre\lib\ext에 복사하기

9. Server, Tomcat 프로젝트 생성

10. eclipse설정
    1. Server 연결
        1. window-> Preferences-> Server-> Installed Runtimes-> add-> Apache->
            Apache Tomcat v5.x-> next-> 디렉토리에 tomcat폴더 설정-> finsh-> ok
        2. window-> Show view-> other-> Servers-> Servers창에서 오른쪽 버튼->
            new-> server-> tomcat v5.x-> 프로젝트 명 추가하기
    2. Tomcat 연결
        1. window-> Preferences-> Tomcat-> v5.5-> Browse-> Adcanced-> Browse-> apply-> ok

11. Html, Jsp 파일 생성
    1. Server 설정
        1. 서버 연결 하기
        2. C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\tomcat-docs\index.html 열기
        3. User Guide-> 9) JDBC DataSources-> 1. Context configuration 복사하기
        4. Servers 프로젝트-> Tomcat v5.5 Server at localhost-config-> server.xml에 추가하기
    2. Tomcat 설정
        1. C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\tomcat-docs\index.html 열기
        2. User Guide-> 9) JDBC DataSources-> 1. Context configuration 복사하기
        3. C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\server.xml에 추가하기
           C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\Catalina\localhost\디렉토리명.xml에 추가하기
            tip) 추가내용
                1.오라클
                <Resource name="jdbc/myoracle"
                          auth="Container"
                          type="javax.sql.DataSource"
                          driverClassName="oracle.jdbc.OracleDriver"
                          url="jdbc:oracle:thin:@127.0.0.1:1521:xe"
                          username="user"
                          password="passwd"
                          maxActive="20"
                          maxIdle="10"
                          maxWait="-1"/>
                2. MySQL
                <Resource name="jdbc/myoracle"
                          auth="Container"
                          type="javax.sql.DataSource"
                          driverClassName="com.mysql.jdbc.Driver"
                          url="jdbc:mysql://localhost:3306/test?autoReconnect=true"
                          username="root"
                          password="passwd"
                          maxActive="20"
                          maxIdle="10"
                          maxWait="-1"/>