2017-11-22 8 views
0
public static void main(String[] argv) { 

     Connection connection = DatabaseDriverExtender.connectOrCreateDataBase(); 
     if (connection == null) { 
     System.out.print("NOOO"); 
     } 
     try { 
     //TODO Check what is in argv 
     //If it is -1 
     /* 
     * TODO This is for the first run only! 
     * Add this code: 
     * DatabaseDriverExtender.initialize(connection); 
     * Then add code to create your first account, an administrator with a password 
     * Once this is done, create an employee account as well. 
     * 
     */ 

argvの内容を確認するにはどうすればよいですか?私はこれに慣れていない。argvには何がありますか?

データベースがすでに作成されているかどうかを確認しているとします。それが-1を生成しなかった場合。どのようにargvにあるのかを確認し、その-1を見つけるのですか?

argvはString []ですか?

+0

「私は、データベースが既に作成さであるかどうか、それはチェックと仮定しています。」どうして? – Dabiuteef

+0

main関数では、argvはコマンドラインから渡された引数の配列になります。 –

+0

@Dabiuteef私はそれをそうしようとしています。 -1が最初に実行されます。私はちょうどあまりにも分かりません –

答えて

0

はい、「argv」は単なる文字列配列です。

はあなたのコードのためにuがちょうどそのような何かを行うことができます。

if (argv.length > 0) { 
//check if argv[0].equals("-1") or something like that 
} 
0

のString [] argvが、端末上のプログラムに入力することができスペースで区切られた文字列のコレクションです。あなたは、このリンクでそれについての詳細を見つけることができます。

What is "String args[]"? parameter in main method Java

0
//when using main method argv cannot be null. But if using somehwere else check if array is not null and then access the elements 
public static void main(String[] argv) { 
    int len=argv.length; 
    System.out.println("No. of elements :"+len); 
    for(int i=0; i<len; i++){ 
     String indexValue=argv[i]; 
     System.out.println("Array Index value:"+indexValue); 
     if("-1".equals(indexValue)){ 
      //value is -1 
     }else{ 
      //value is not -1 
     } 
    } 
} 
関連する問題