Java에서 OS 알아내기


[CODE type="java"]class ShowOS{
[tab]public static void main(String[] args){
[tab][tab]try{
[tab][tab][tab]String osName = System.getProperty("os.name");
[tab][tab][tab]System.out.println(osName);
[tab][tab]}
[tab][tab]catch (RuntimeException sr){
[tab][tab][tab]System.err.println("e : " + sr);
[tab][tab]}
[tab]}
}[/HTML][/CODE]
2006/07/06 12:02 2006/07/06 12:02

java + mysql

개발/Java 2006/07/06 11:32
Java에서 MySql 사용하기

1) 서버쪽 설정
방화벽에서 3306 포트를 열어준다 tcp,udp
mysql 의 db테이블에 해당 사용자의 접근권한을 %(anywhere)로 설정

mysqld 및 방화벽 서비스 재시작

2) 클라이언트 쪽
mysql.com 에서 jdbc드라이버를 다운받아 설치한다

Example
[CODE type="java"]
try {
[tab][tab]Class.forName("com.mysql.jdbc.Driver"); // 드라이버 위치 지정
[tab][tab]} catch (ClassNotFoundException e1) {
[tab][tab][tab]e1.printStackTrace();
[tab][tab]}
[tab][tab]String url = "jdbc:mysql://주소:포트/DB이름";
[tab][tab]String que;
[tab][tab]ResultSet rs;
[tab][tab]try{
[tab][tab]Connection con = DriverManager.getConnection(url,USERID,PASSWD);
[tab][tab]Statement stmt = con.createStatement();
[tab][tab]
[tab][tab]rs = stmt.executeQuery("select * from Menu");
[tab][tab]
[tab][tab]while(rs.next()){
[tab][tab][tab]int theInt = rs.getInt("menu_id");
[tab][tab][tab]String name = rs.getString("name");
[tab][tab][tab]int price = rs.getInt("price");
[tab][tab][tab]
[tab][tab][tab]System.out.println( theInt + "/ " + name +" / " + price );[tab][tab][tab]
[tab][tab][tab]
[tab][tab]}
[tab][tab]}catch (Exception e) {
[tab][tab][tab]System.out.println(e);
[tab][tab]}[tab][tab][tab]
[tab][tab]
[tab]}
[/HTML][/CODE]
스샷
http://user.sempee.com/~kfmes/imgpds/javadb.png
2006/07/06 11:32 2006/07/06 11:32

어제
IgetLinux 를 설치하고,

gaim으로 봇에게 메세지를 날려봤다

그런데 이게 왠일인가!!
msn messenger, webmessenger, jmsn, minimsn,
심지어는 폰으로 해도 응답이 잘 작동하던
봇이 이상하게도 정상적으로 작동하질 않는 것이었다.

터미널 창을열고
ssh 접속을해서,

상태를 봤다

gaim에서 보낸 메세지에 줄바꿈이 들어가 전송이 되는것이었다.

윈도우로 돌아와서,
eclipse 디버깅으로,
gaim에서 넘어온 메세지를 보니
\r\n 이 앞에 붙어서 날라오는걸 확인했다


String rm = mime.getMessage();; // args[0];
               if(rm.startsWith("\r\n")){
                       rm = rm.substring(2);//gaim 에서 메세지들어올때 \r\n이 붙어서 들어옴
               }
이렇게 코드를 수정했다.
2006/01/14 11:17 2006/01/14 11:17

Thread Test

개발/Java 2006/01/05 17:44

[CODE type="java"]
/** 쓰레드 연습 **/
class Data{
[tab]
[tab]private String data;
[tab]private boolean is_saved = false;
[tab]
[tab]public synchronized void setData(String arg){
[tab][tab]
[tab][tab] try{
[tab][tab][tab] 
[tab][tab][tab] 
[tab][tab][tab]  if(is_saved){
[tab][tab][tab][tab]   wait();
[tab][tab][tab]  }
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab]  System.out.println("SET error");
[tab][tab] }
[tab][tab]
[tab][tab] data = arg;
[tab][tab] is_saved = true;
[tab][tab] notify();
[tab][tab]
[tab]}
[tab]public synchronized  String getData(){
[tab][tab]
[tab][tab] try{
[tab][tab][tab]  if(!is_saved)
[tab][tab][tab][tab]   wait();
[tab][tab][tab] 
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab]  System.out.println("GET error");
[tab][tab] }
[tab][tab]
[tab][tab] String r = data;
[tab][tab] data = "";
[tab][tab] is_saved =false;
[tab][tab] notify();
[tab][tab] return r;
[tab]}
[tab]
[tab]
[tab]public boolean is_saved(){
[tab][tab] return is_saved;[tab][tab] 
[tab]}
[tab]
}

class Producer extends Thread{
[tab]Data s;
[tab]Producer(String msg, Data ss){
[tab][tab] s=ss;
[tab][tab] System.out.println(msg);[tab][tab] 
[tab]}
[tab]public void run(){
[tab][tab] int i=0;

[tab][tab] while(i<10){
[tab][tab][tab]  try{
[tab][tab][tab]  sleep((long)(Math.random()*1000));
[tab][tab][tab]  }
[tab][tab][tab]  catch (Exception e) {
[tab][tab][tab][tab]   // TODO: handle exception
[tab][tab][tab]  }
[tab][tab][tab] 
[tab][tab][tab]  System.out.println( "producer is running : " +i);
[tab][tab][tab]  s.setData("DATA ("+i+"): " + produce());
[tab][tab][tab][tab]   i++;
[tab][tab]
[tab][tab] }//end while

[tab]}//end run
[tab]
[tab]private String produce(){
[tab][tab] int r ;
[tab][tab] r =(int)( Math.random()*10);
[tab][tab] return "" + r;
[tab]}
[tab]
}
class Consumer extends Thread{
[tab]Data s;[tab]
[tab]
[tab]Consumer(String msg,Data ss){
[tab][tab] s = ss;
[tab]
[tab][tab] System.out.println(msg);
[tab]}
[tab]
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] String data="";

[tab][tab] while(i<10){
[tab][tab][tab]  try{
[tab][tab][tab][tab]   sleep((long)(Math.random()*1000));
[tab][tab][tab][tab]   }
[tab][tab][tab][tab]   catch (Exception e) {
[tab][tab][tab][tab][tab]    // TODO: handle exception
[tab][tab][tab][tab]   }
[tab][tab][tab][tab]  
[tab][tab][tab]  System.out.println( "consumer is running : " + i);
[tab][tab][tab]  data =s.getData();
[tab][tab][tab]  System.out.println(">> " +  data);

[tab][tab][tab]  i++;

[tab][tab][tab] 
[tab][tab] }//end while

[tab]}//end run[tab]
}

class Ttest{
[tab]public static void main(String args[])
[tab]{
[tab][tab] Data data = new Data();
[tab][tab] Producer t1 = new Producer("P thread is ready", data);
[tab][tab] Consumer c1 = new Consumer("C thread is ready", data);
[tab][tab]
[tab][tab]
[tab][tab] t1.start();
[tab][tab] c1.start();
[tab][tab]
[tab][tab]
[tab][tab]
[tab][tab][tab][tab]  
[tab]}[tab][tab] 
}

/**

class Data{
[tab]
[tab]private String data;
[tab]private boolean is_saved = false;
[tab]
[tab]public void setData(String arg){
[tab][tab] data = arg;
[tab][tab] is_saved = true;
[tab]}
[tab]public String getData(){
[tab][tab] String r = data;
[tab][tab] data = "";
[tab][tab] is_saved =false;
[tab][tab] return r;
[tab]}
[tab]
[tab]
[tab]public boolean is_saved(){
[tab][tab] return is_saved;[tab][tab] 
[tab]}
[tab]
}

class Producer extends Thread{
[tab]Data s;
[tab]Producer(String msg, Data ss){
[tab][tab] s=ss;
[tab][tab] System.out.println(msg);[tab][tab] 
[tab]}
[tab]public void run(){
[tab][tab] int i=0;

[tab][tab] try{
[tab][tab][tab]  while(i<10){
[tab][tab][tab][tab]  
[tab][tab][tab][tab]   System.out.println( "producer is running : " +i);
[tab][tab][tab][tab]   if(s.is_saved()){
[tab][tab][tab][tab][tab]    yield();
[tab][tab][tab][tab]   }
[tab][tab][tab][tab]   else{
[tab][tab][tab][tab][tab]    s.setData("DATA ("+i+"): " + produce());
[tab][tab][tab][tab][tab]    i++;
[tab][tab][tab][tab]   }
[tab][tab][tab][tab]  
[tab][tab][tab]  }//end while
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab]  System.out.println(e);
[tab][tab][tab]  // TODO: handle exception
[tab][tab] }
[tab]}//end run
[tab]
[tab]private String produce(){
[tab][tab] int r ;
[tab][tab] r =(int)( Math.random()*10);
[tab][tab] return "" + r;
[tab]}
[tab]
}
class Consumer extends Thread{
[tab]Data s;[tab]
[tab]
[tab]Consumer(String msg,Data ss){
[tab][tab] s = ss;
[tab]
[tab][tab] System.out.println(msg);
[tab]}
[tab]
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] String data="";

[tab][tab] try{
[tab][tab][tab]  while(i<10){
[tab][tab][tab][tab]   System.out.println( "consumer is running : " + i);
[tab][tab][tab][tab]   if(s.is_saved()){
[tab][tab][tab][tab][tab][tab]     data =s.getData();
[tab][tab][tab][tab][tab][tab]     System.out.println(">> " +  data);
[tab][tab][tab][tab][tab][tab]     //notifyAll();
[tab][tab][tab][tab][tab][tab]     i++;
[tab][tab][tab][tab]   }
[tab][tab][tab][tab]   else{
[tab][tab][tab][tab][tab]    yield();
[tab][tab][tab][tab][tab]    yield();
[tab][tab][tab][tab][tab]   
[tab][tab][tab][tab][tab]    //this.wait();
[tab][tab][tab][tab][tab]    //this.suspend();
[tab][tab][tab][tab]   }
[tab][tab][tab][tab]  
[tab][tab][tab]  }//end while
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab]  System.out.println(e);
[tab][tab][tab]  // TODO: handle exception
[tab][tab] }
[tab]}//end run[tab]
}

class Ttest{
[tab]public static void main(String args[])
[tab]{
[tab][tab] Data data = new Data();
[tab][tab] Producer t1 = new Producer("P thread is ready", data);
[tab][tab] Consumer c1 = new Consumer("C thread is ready", data);
[tab][tab]
[tab][tab]
[tab][tab] t1.start();
[tab][tab] c1.start();
[tab][tab]
[tab][tab]
[tab][tab]
[tab][tab][tab][tab]  
[tab]}[tab][tab] 
}
**/

[/HTML][/CODE]

2006/01/05 17:44 2006/01/05 17:44

msn bot
SBsession 처리 작업도중 ;
이 문제로 몇시간동안 삽질끝에 method overriding으로 해결

class SBField{
       public long SB;
       public int Code;
       
       
       public boolean equals(Object obj){
               SBField f = (SBField)obj;
               
               if(this.SB==f.SB && this.Code == f.Code)
                       return true;
               
               return false;
       }
}


...
...
...

public int find(SBField element){
       
       ListIterator li = list.listIterator();
       
       while(li.hasNext()){
               //System.out.println( li.nextIndex() + ":" + li.next().equals((Object)element) );
               
               Object next = li.next();
               
               //System.out.println(next);
               if(next.equals((Object)element))
                       return li.nextIndex()-1;

       }
       
       return -1;
}
2006/01/01 16:49 2006/01/01 16:49

HTMLtest

개발/Java 2005/12/24 11:46
html 읽기 소스
2005/12/24 11:46 2005/12/24 11:46

http://www.xrath.com/devdoc/msnm $ export CVS_RSH=ssh jmsn download $  cvs -z3 -d:pserver:[email protected]:/cvsroot/jmsn co -P jmsn jmsn lib download $ cvs -z3 -d:pserver:[email protected]:/cvsroot/jmsn co -P msnmlib
2005/12/19 08:22 2005/12/19 08:22

java msn bot project start
2005/12/18 15:56 2005/12/18 15:56