View Javadoc

1   /**************************************************************************
2   Copyright 2005 Webstersmalley
3   
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  *************************************************************************/
16  
17  
18  package com.webstersmalley.utils.db;
19  
20  import java.io.BufferedReader;
21  import java.io.FileInputStream;
22  import java.io.FileNotFoundException;
23  import java.io.InputStreamReader;
24  
25  /***
26   * @author Matthew Smalley
27   */
28  public class SQLFileParser
29  {
30      private String filename;
31      private BufferedReader reader;
32      
33      public SQLFileParser(String filename) throws FileNotFoundException
34      {
35          this.filename = filename;
36          openFile();
37      }
38      
39      public void openFile() throws FileNotFoundException
40      {
41          reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
42      }
43  
44      public String nextStatement() throws Exception
45      {
46          StringBuffer sqlStatement = new StringBuffer();
47          String line;
48          line = reader.readLine();
49          while (line != null)
50          {
51              line = line.trim();
52              sqlStatement.append(line);
53              if (line.endsWith(";"))
54              {
55                  return sqlStatement.toString();
56              }
57              line = reader.readLine();
58          }
59          String statement = sqlStatement.toString();
60          if (statement == null || statement.trim().equals(""))
61          {
62              return null;
63          }
64          else
65          {
66              throw new Exception ("Error - unexpected EOF");
67          }
68      }
69      
70      
71      public static void main(String[] args)
72      {
73      }
74  }