Содержимое файлов для запросов SQL:
Код: Выделить всё
#Query Number
SELECT A_COL,B_COL,C_COL
FROM A_TABLENAME
#QUERY NUMBER
SELECT A_COL,B_COL,C_COL
FROM B_TABLENAME
Код: Выделить всё
public ArrayList createQueries(String path) throws IOException
{
String queryLine = new String();
StringBuffer sBuffer = new StringBuffer();
listOfQueries = new ArrayList();
try
{
FileReader fr = new FileReader(new File(path));
BufferedReader br = new BufferedReader(fr);
//read the SQL file line by line
while((queryLine = br.readLine()) != null)
{
// IGNORE COMMENTS BEGINNING WITH #
int indexOfCommentSign = queryLine.indexOf('#');
if(indexOfCommentSign != -1)
{
if(queryLine.startsWith("#"))
{
queryLine = new String("");
}
else
queryLine = new String(queryLine.substring(0, indexOfCommentSign-1));
}
// IGNORE COMMENTS BEGINNING WITH --
indexOfCommentSign = queryLine.indexOf("--");
if(indexOfCommentSign != -1)
{
if(queryLine.startsWith("--"))
{
queryLine = new String("");
}
else
queryLine = new String(queryLine.substring(0, indexOfCommentSign-1));
}
// IGNORE COMMENTS SURROUNDED BY /* */
indexOfCommentSign = queryLine.indexOf("/*");
if(indexOfCommentSign != -1)
{
if(queryLine.startsWith("#"))
{
queryLine = new String("");
}
else
queryLine = new String(queryLine.substring(0, indexOfCommentSign-1));
sBuffer.append(queryLine + " ");
// IGNORE ALL CHARACTERS WITHIN THE COMMENT
do
{
queryLine = br.readLine();
}
while(queryLine != null && !queryLine.contains("*/"));
indexOfCommentSign = queryLine.indexOf("*/");
if(indexOfCommentSign != -1)
{
if(queryLine.endsWith("*/"))
{
queryLine = new String("");
}
else
queryLine = new String(queryLine.substring(indexOfCommentSign+2, queryLine.length()-1));
}
}
// THE + " " IS NECESSARY, BECAUSE OTHERWISE THE CONTENT BEFORE AND AFTER A LINE BREAK ARE CONCATENATED
// LIKE E.G. A.XYZ FROM BECOMES A.XYZFROM OTHERWISE AND CAN NOT BE EXECUTED
if(queryLine != null)
sBuffer.append(queryLine + " ");
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... le-in-java
Мобильная версия