1
  • I have the below servlet code.
  • While printing the below line in console, it should be printed in red color. "*Connection name "+cname+" already exists. Please try with another name". how to get this.

My servlet code:

 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(); } 
2
  • You are writing code to access database and write some text in console in your servlet !!! Commented Feb 25, 2013 at 8:48
  • @Apurv the problem is not who taught her Java, is who taught her web programming, because there are lot of misconceptions in the question (and in the code). Commented Feb 25, 2013 at 8:49

1 Answer 1

0

You can try jlibs (http://code.google.com/p/jlibs/wiki/AnsiColoring) which has Ansi Colors in Console Output.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.