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中的内容?我对此并不熟悉。
我假设它检查数据库是否已经创建。如果它没有创建-1。我如何检查argv中的内容并找到它的-1?
argv是一个String []?
答案 0 :(得分:0)
是的," argv"只是一个String数组。
对于你的代码,你可以做类似的事情:
if (argv.length > 0) {
//check if argv[0].equals("-1") or something like that
}
答案 1 :(得分:0)
String [] argv是一个字符串的集合,由空格分隔,可以在终端上输入程序。您可以在此链接上找到有关它的更多详细信息:
答案 2 :(得分: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
}
}
}