1
- 我有下面的servlet代碼。
- 在控制檯中打印下面的行時,應該以紅色打印。 「*連接名稱」+ cname +「已存在,請用另一個名字嘗試」。如何得到這個。
我的servlet代碼:使用java設置字符串顏色
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();
}
明白了......謝謝 – Rachel 2013-02-25 08:17:57
您正在編寫代碼來訪問數據庫並在'servlet'中編寫一些控制檯文本! – Apurv 2013-02-25 08:48:09
@Apurv問題不在於誰教她的Java,是誰教她的網絡編程,因爲在問題(和代碼中)中存在許多錯誤觀念**。 – 2013-02-25 08:49:31