I wrote a SQL parser, the code works fine and I can see proper output at the end of parsing. Now I am trying to display the parsed output in a JSP. In order to do that, I have setup the project on IntelliJ as show in the image below.
The parser I have written earlier has its main method inside getTableColumn
which is marked in RED box in the image.
It looks like this.
public class getTableColumn {
..
..
public static void main(String args[]) throws SQLException {
ReadQueries rq = new ReadQueries("query");
String output = rq.getData();
....
....
....
....
}
}
ReadQueries is the class where I declared all the custom methods to parse the SQL. The method getData
returns the parsed output and it is present in the String output
. I am trying to display the value of output
in a jsp.
I renamed the main method in getTableColumn
to processQuery
so that I can call it from other classes as well.
Based on a drop down in the JSP, I am trying to pass a string value into getTableColumn's processQuery
as below.
import com.query.data.ReadQueries;
import com.table.modules.TableModules;
import com.where.WhereData;
import gudusoft.gsqlparser.EDbVendor;
import gudusoft.gsqlparser.IMetaDatabase;
import save.querydata.InsertColumns;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
class sampleMetaDB implements IMetaDatabase {
String columns[][] = { {"server", "db", "schema", "TBL_BBGPOS_REP", "M_TP_PFOLIO"
}, { "server", "db", "schema", "A_FXPOSITIONDEL_REP", "M_FXDELTA"},
{"server", "db", "schema", "A_FXPOSITIONDEL_REP", "M_CLOSING_E" },
{"server", "db", "schema", "A_FXPOSITIONDEL_REP", "M_FXDELTA_Z"}
};
public boolean checkColumn(String server, String database, String schema, String table, String column) {
boolean bServer, bDatabase, bSchema, bTable, bColumn, bRet = false;
for (int i = 0; i < columns.length; i++) {
if ((server == null) || (server.length() == 0)) {
bServer = true;
} else {
bServer = columns[i][0].equalsIgnoreCase(server);
}
if (!bServer) continue;
if ((database == null) || (database.length() == 0)) {
bDatabase = true;
} else {
bDatabase = columns[i][1].equalsIgnoreCase(database);
}
if (!bDatabase) continue;
if ((schema == null) || (schema.length() == 0)) {
bSchema = true;
} else {
bSchema = columns[i][2].equalsIgnoreCase(schema);
}
if (!bSchema) continue;
bTable = columns[i][3].equalsIgnoreCase(table);
if (!bTable) continue;
bColumn = columns[i][4].equalsIgnoreCase(column);
if (!bColumn) continue;
bRet = true;
break;
}
return bRet;
}
}
public class getTableColumn {
private static File[] listFiles(File sqlFiles) {
List<File> children = new ArrayList<File>();
if (sqlFiles != null)
listFiles(sqlFiles, children);
return children.toArray(new File[0]);
}
private static void listFiles(File rootFile, List<File> children) {
if (rootFile.isFile())
children.add(rootFile);
else {
File[] files = rootFile.listFiles();
for (int i = 0; i < files.length; i++) {
listFiles(files[i], children);
}
}
}
public String processQuery(String category) throws SQLException {
EDbVendor vendor = EDbVendor.dbvmysql;
System.out.println("Processing " + vendor.toString() + "...");
TGetTableColumn getTableColumn = new TGetTableColumn(vendor);
getTableColumn.showDetail = false;
getTableColumn.showSummary = true;
getTableColumn.showTreeStructure = false;
getTableColumn.showBySQLClause = false;
getTableColumn.showJoin = false;
getTableColumn.showColumnLocation = true;
getTableColumn.linkOrphanColumnToFirstTable = false;
getTableColumn.showIndex = false;
getTableColumn.showDatatype = true;
getTableColumn.listStarColumn = true;
getTableColumn.setMetaDatabase(new sampleMetaDB());
String sqlQuery = queryDetails[1];
getTableColumn.run(sqlQuery, false);
String issue = category;
ReadQueries rq = new ReadQueries(issue);
String outputQuery = rq.getQueries();
long t = System.currentTimeMillis();
EDbVendor vendor = EDbVendor.dbvmysql;
return outputQuery();
}
private static void displayInitInformation() {
System.out.println("Usage: java getTableColumn [/f <path_to_sql_file>] [/d <path_to_directory_includes_sql_files>] [/t <database type>] [/<show option>]");
System.out.println("/f: specify the sql file path to analyze.");
System.out.println("/t: option, set the database type. Support oracle, mysql, mssql, db2, netezza, teradata, informix, sybase, postgresql, hive, greenplum and redshift, the default type is oracle");
System.out.println("/showSummary: default show option, display the summary information.");
System.out.println("/showDetail: show option, display the detail information.");
System.out.println("/showTreeStructure: show option, display the information as a tree structure.");
System.out.println("/showBySQLClause: show option, display the information group by sql clause type.");
System.out.println("/showJoin: show option, display the join table and column.");
}
}
The problem I see is that I am unable to create an object of getTableColumn
in my servlet class.
package com.servlets;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/getdata.do")
public class DataServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String issue = request.getParameter("reportSelection");
getTableColumn gt = new getTableColumn();
if ("Latency".equals(issue)) {
getTableColumn gt = new getTableColumn();
System.out.println("Latency");
} else if ("DataQuality".equals(issue)) {
System.out.println("Data quality");
} else if ("Outage".equals(issue)) {
}
}
}
The line: getTableColumn gt = new getTableColumn();
says Cannot resolve symbol 'getTableColumn'
. I tried to write import statement of that class but it didn't work either.
I don't understand how to fix this problem. Could anyone let me know how can I fix it ?