1
  • 以下のサーブレットコードがあります。
  • コンソールで以下の行を印刷すると、赤色で印刷されるはずです。"*接続名 "+cname+" は既に存在します。別の名前で試してください。". これを取得する方法。

私のサーブレットコード:

  try{
            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
            con =DriverManager.getConnection("jdbc:oracle:thin:@"+host+":"+port+"/"+service,username,password);
            con.setAutoCommit(false);
            if(con!=null){
                if(key == null){ 
                    out.println("Connected Successfully");
                    String rootPath=request.getSession().getServletContext().getRealPath("/");
                    System.out.println(rootPath);
                    String propPath=rootPath+"/WEB-INF/";
                    PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter(propPath+"importedDB.properties", true)));
                    out1.println(cname+"=jdbc:oracle:thin:@"+host+","+port+","+service+","+username+","+password);
                    out1.close();
                }
                else{                   
                    out.println("*Connection name "+cname+" already exists. Please try with another name");
                }
             }else{
                 out.println("Error in getting connection");
             }
        }catch(Exception e){
            e.printStackTrace();
        }
4

1 に答える 1

0

コンソール出力に Ansi Colors があるjlibs ( http://code.google.com/p/jlibs/wiki/AnsiColoring ) を試すことができます。

于 2013-02-25T09:31:40.127 に答える