我正在寫一個java函數,我試圖建立一個數據庫查詢但字符串的元素不被替換。麻煩準備數據庫查詢
這是我的查詢:
BOOK
Host:
Database: AVIATION
Generation Time: May 12, 2015 at 07:32:00 AM
Generated by: phpMyAdmin 3.5.7/MySQL 5.6.10
SQL query: SHOW columns FROM BOOK
Rows: 4
Field Type Null Key Default Extra
timestamp varchar(15) NO NULL
concept varchar(50) NO NULL
page varchar(5) YES NULL
chapter varchar(20) NO NULL
section varchar(20) YES NULL
course varchar(10) NO NULL
book varchar(20) YES NULL
module varchar(2) YES NULL
comments varchar(250) YES NULL
Java函數
public String prepareQuery(String q) {
String[] array = q.split("\n");
String q2 = " ";
q2 += "CREATE TABLE BOOK (\n";
for (int i = 10; i < array.length; i++) {
q2 += array[i];
q2 += ",\n";
}
q2 += "\n);";
// Replacing double spaces to single space
q2 = q2.replaceAll(" ", " ");
// this part is not working as if i see output YES NULL is still there
q2 = q2.replaceAll(" Yes NULL ,", ",");
// changing NO to NULL and working
q2 = q2.replaceAll("NO" , "NOT");
return q2;
}
此功能將取代一切,除了 「是空」。
不知道你正在努力實現的,使用StringBuilder而不是字符串添加字符串作爲字符串不能改變的對象。 – DeepInJava