I created a spring boot project, but then realized I dont want to run the app on the server, just wanted to implement my logic in the main method. I have done so far, and I cant seem to figure out what am I missing.
I have a class MainLogic.java
@Configuration
public class MainLogic {
JdbcTemplate jdbcTemplate;
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
private String sqlQuery = "";
public String getID(@RequestParam String id, @RequestParam(required=false) String date){
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
dateFormat.setLenient(false);
String path = "";
sqlQuery= "SELECT i.abc_id as id"
+ "FROM ABCDetail i \n"
+ "WHERE i.abc_id = "+id+"\n"
}
#46: List<ABC> ABCdetails = jdbcTemplate.query(sqlQuery, new BeanPropertyRowMapper<ABC>(ABC.class));
ABCdetails.toString();
final StringBuilder textData = new StringBuilder();
final String headers = "ID";
textData.append(headers).append("\n");
for (final ABC abcDetail : ABCdetails) {
final String line = ((abcDetail.getID()==null)?"": abcDetail.getID()) + "\t" + ((abcDetail.getEXT_TYPE()==null)?"";
textData.append(line).append("\n");
}
try {
File tempDir = new File(System.getProperty("java.io.tmpdir"));
File tempFile = File.createTempFile("output", ".tmp", tempDir);
FileWriter fileWriter = new FileWriter(tempFile, true);
System.out.println(tempFile.getAbsolutePath());
path = tempFile.getAbsolutePath();
BufferedWriter bw = new BufferedWriter(fileWriter);
bw.write(textData.toString());
bw.close();
}catch (Exception e) {
// TODO: handle exception
}
return path;
}
and my main class
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(MainLogic.class);
MainLogic ml = ctx.getBean(MainLogic.class);
String newPath = "";
if(args.length > 0) {
try {
System.out.println("Passing the argument to the controller: "+ ml.getID(args[0], args[1]));
}
I am getting a null pointer exception in MainLogic at line #46, can someone please help me. or can anyone suggest me a better to do this? I am new to JAVA.
