Skip to main content

Posts

Showing posts from 2021

Intellij : How to add @author comment to every new class

 Introduction In this tutorial, we will learn how to add @author comments to every new class that we create. We can achieve it using either of the following two solutions Solution 1:  Automatically add @author comments to every new class using Files and Code Templates Open File -> Settings -> Editor -> File and Code Templates -> Includes Click on Includes . Under File Header , enter the following comments text /**  * @author ${USER}  * @Date ${DATE}   */ Intellij - add @author comments Solution 2: Autocompletion of @author Open File  ->  Settings  ->  Editor  -> Live Templates Select Java and then click on + button In Abbreviation, enter @a In template text , enter the following comments           /**             * @author ${USER}             * @Date ${DATE}            */ In option , Expands with select SPACE Intellij - Autocompletion @author You can simply add the @author comments by typing @a and then click SPACE

Java : How to convert String to Date?

 Introduction In this post, we will learn how to convert Java String to Date  Example: import java.util.Date; public class DateConversion { public static void main(String[] args) {      SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");      try { Date date = sdf.parse("19-09-2020"); System.out.println(date);      } catch (Exception ex) { ex.printStackTrace();      } } } In Java 8 and onward versions, we can use the LocalDate and DateTimeFormatter class to convert a String to a LocalDate object. We will use the parse method of the LocalDate class to perform this conversion Example (using Java 8+ versions) import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class DateConversion { public static void main(String[] args) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); try { LocalDate date = LocalDate.parse("19-09-2020",formatter); System.out.println(da

Java : How to convert java.util.Date to java.sql.Date?

 Introduction In this article, we will learn how to convert java.util.Date to java.sql.Date Example: import java.util.Calendar; import java.util.Date; public class DateConversion { public static void main(String[] args) { Date date = Calendar.getInstance().getTime(); java.sql.Date sqlDate = new java.sql.Date( date.getTime()); } } Please note that both these Date classes are outdated now. Use java.Time  classes instead of legacy java.util.Date & java.sql.Date with JDBC 4.2 or later. Use Instant class instead of java.util.Date Use LocalDate instead of java.sql.Date

Java : How to convert java.util.Date to Gregorian Calendar Date Format?

Introduction Below example demonstrates how to convert java.util.Date to Gregorian Calendar  Example import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class DateToGregorianCalendar { public static void main(String[] args) { Date date = Calendar.getInstance().getTime(); GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(date); } }

ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view

 Problem ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view 12054. 00000 -  "cannot set the ON COMMIT refresh attribute for the materialized view" *Cause:    The materialized view did not satisfy conditions for refresh at commit time. *Action:   Specify only valid options. Solution  You can not use the DISTINCT keyword in your Materialized View query, rather use Group By instead of distinct You can not use the standard JOIN in your query, instead, you should use the old-styled Join like A, B where A.ID = B.ID     

Spring Boot Maven plugin - How to deploy WAR to an external tomcat's webapp folder?

 Introduction Spring Boot Maven plugin by default generates the WAR file inside the target folder. In this post, I will explain how to copy the generated war file to an external Tomcat's webapps folder using Spring Boot Maven plugin. In my earliest post , you can learn how to package a Spring Boot application as WAR.  Solution Step 1  Follow this link to specify the packaging as WAR in pom.xml and also to configure the  SpringBootServletInitializer class Step 2 (optional) Specify a cleaner name for WAR using the finalName tag in pom.xml  <finalName>auth</finalName> Step 3 Specify the outputDirectory directory      <build> <finalname>auth</finalname> <plugins> <plugin>           <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <configuration>           <outputdirectory>D:/Development Utils/apache-tomcat-9.0.30/webapps</outputdirectory>