---
title: "关于如何在NetBeans6.1中向单个文件添加命令行参数问题的解决!!"
author: "ranfow"
date: "2008-06-29T08:07:55Z"
tags: []
categories: ["企业架构"]
slug: "netbeans6-1"
draft: false
lastmod: "2008-06-29T08:07:55Z"
id: 209054
url: "https://ranfow.iteye.com/blog/209054"
---

这几天在论坛上看到以前有人问,在NetBeans中如和向单个.java 文件提供命令行参数  
以前对NetBeans 也不是很熟悉,现在对NetBeans了解多了,就知道怎么做了.

首先打开项目的属性,即右键项目选择最底下的项目属性. 然后在生成节点下选择运行选项,然后在  
右边的选项里选择你要调试的主类(即含有main()函数的类),具体看截图:![](http://www.blogjava.net/images/blogjava_net/gml520/args.jpg)

设置好后运行项目,记住运行的是项目而不是单个文件, NetBeans 运行项目的时候是根据你提供的  
主类来运行的,相当于运行了单个文件 .^\_^

下面是测试代码:  
我用的是JDBC 进行测试. 我把让密码从命令行里得到.用的是MySQL的数据库,大家可以根据自己的  
需要来改. 我把密码root 写到了命令行里.

package  gml.JDBC;

import  java.sql. * ;

public   class  TestSQL {

     public   static   void  main(String\[] args) {

        Connection cnn  =   null ;  
        Statement stmt  =   null ;  
        ResultSet rs  =   null ;  
         try  {  
            Class.forName( " com.mysql.jdbc.Driver " );  
            cnn  =  DriverManager.getConnection( " jdbc:mysql://localhost:3306/bbs " ,  " root " , args\[ 0 ]);  
            stmt  =  cnn.createStatement();  
            rs  =  stmt.executeQuery( " select * from users " );  
            System.out.println( " ID      Name " );  
             while  (rs.next()) {  
                System.out.print(rs.getString( " user\_ID " )  +   " \\t " );  
                System.out.println(rs.getString( " user\_Name " ));  
            }  
        }  catch  (ClassNotFoundException e) {  
            e.printStackTrace();  
        }  catch  (SQLException e) {  
            e.printStackTrace();  
        }  finally  {  
             try  {  
                 if  (rs  !=   null ) {  
                    rs.close();  
                    rs  =   null ;  
                }  
                 if  (stmt  !=   null ) {  
                    stmt.close();  
                    stmt  =   null ;  
                }  
                 if  (cnn  !=   null ) {  
                    cnn.close();  
                    cnn  =   null ;  
                }  
            }  catch  (SQLException e) {  
                e.printStackTrace();  
            }  
        }  
    }  
}

**小结一下:**

     NetBeans 给我们提供了很多的功能,只是有的时候我们不知道怎么用,然后就会思念使用  
eclipse 的时光了,其实只要自己多试几次 就会很快上手的.  
最后希望这篇文章能够对想向NetBeans中向单个.java 文件提供命令行参数的朋友 有帮助.

 

原文链接：http://www.blogjava.net/gml520/archive/2008/06/08/206727.html