Skip to content

Commit 322cd81

Browse files
authored
Modified Input taking part
Modifying the input mechanism, where user is given option to quit
1 parent 4c91f43 commit 322cd81

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

src/com/rishal/application/Application.java

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,50 @@
77
import java.lang.reflect.Method;
88

99
import com.rishal.exception.InvalidSqlException;
10+
1011
/**
1112
* Main Class used to launch the application.
13+
*
1214
* @author Rishal
1315
*
1416
*/
1517
public class Application {
16-
17-
public static void main(String[] args) throws IOException, InvalidSqlException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
18-
//Taking Query input from user
19-
LoadData a=LoadData.getInstance();
20-
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
21-
22-
System.out.println("CommandLine SQL- Enter the SQl query to get the result");
23-
String inputQuery=br.readLine();
24-
QueryType query=new QueryType();
25-
QueryType.Type typeOfQuery = query.getLineType(inputQuery);
26-
if(!typeOfQuery.equals(QueryType.Type.NOMATCH))
27-
{
28-
Class<?> c= Class.forName("com.rishal.queryOperation"+"."+typeOfQuery.toString());
29-
Object t = c.newInstance();
30-
Method method = c.getDeclaredMethod("display", String.class);
31-
method.invoke(t, inputQuery);
32-
}
33-
else
34-
{
35-
throw new InvalidSqlException("Invalid Sql! Please enter valid SQL query.");
18+
19+
public static void main(String[] args) throws IOException,
20+
InvalidSqlException, ClassNotFoundException,
21+
InstantiationException, IllegalAccessException,
22+
NoSuchMethodException, SecurityException, IllegalArgumentException,
23+
InvocationTargetException {
24+
// Taking Query input from user
25+
LoadData a = LoadData.getInstance();
26+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
27+
System.out
28+
.println("CommandLine SQL- Enter the SQl query to get the result. Enter (Exit/Quit) to exit!");
29+
String inputQuery = "";
30+
while (!inputQuery.equalsIgnoreCase("Exit")
31+
|| !inputQuery.equalsIgnoreCase("Quit")) {
32+
inputQuery = br.readLine();
33+
QueryType query = new QueryType();
34+
QueryType.Type typeOfQuery = query.getLineType(inputQuery);
35+
if (!typeOfQuery.equals(QueryType.Type.NOMATCH)) {
36+
Class<?> c = Class.forName("com.rishal.queryOperation" + "."
37+
+ typeOfQuery.toString());
38+
Object t = c.newInstance();
39+
Method method = c.getDeclaredMethod("display", String.class);
40+
method.invoke(t, inputQuery);
41+
} else if (!(inputQuery.equalsIgnoreCase("Exit"))
42+
&& !(inputQuery.equalsIgnoreCase("Quit"))) {
43+
throw new InvalidSqlException(
44+
"Invalid Sql! Please enter valid SQL query.");
45+
} else if (inputQuery.equalsIgnoreCase("Exit")
46+
|| inputQuery.equalsIgnoreCase("Quit")) {
47+
System.out.println("Sql Engine Closing !Bye");
48+
break;
49+
50+
}
51+
3652
}
3753

3854
}
3955

40-
}
56+
}

0 commit comments

Comments
 (0)