How to add Oracle JDBC driver in your Maven local repository

Here’s a simple guide to show you how to add an Oracle JDBC driver into your Maven local repository, and also how to reference it in pom.xml Tested with Oracle database 19c and Java 8 Note Due to Oracle license restrictions, the Oracle JDBC driver is not available in the public Maven repository. To use …

Read more

java.lang.ClassNotFoundException : javassist.util.proxy.MethodFilter

Problem Using Hibernate 3.6.3, but hits this javassist not found error, see below for error stacks : Caused by: java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter … at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:77) … 16 more Caused by: java.lang.ClassNotFoundException: javassist.util.proxy.MethodFilter at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) … 21 more Solution javassist.jar is missing, and you …

Read more

Generate source code jar for Maven based project

The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging. 1. Maven Source Plugin Add maven-source-plugin in your pom.xml file. pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> …

Read more

Generate javadoc jar for Maven based project

The “maven-javadoc” plugin uses “JDK\bin\javadoc.exe” command to generate javadocs, pack in jar file and deploy along with your project. 1. Maven JavaDoc Plugin Add “maven-javadoc” plugin in your “pom.xml” file. File : pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mkyong</groupId> <artifactId>mkyongcore</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>mkyongcore project</name> <url>http://maven.apache.org</url> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> <id>attach-javadocs</id> <goals> …

Read more

Maven + WebDAV – Embedded error: Failed to transfer file: … Return code is: 405

Problem A pom.xml file, when “mvn site:deploy” is issued, the site doesn’t deploy to the defined server and hits the HTTP error code : 405. File : pom.xml <project …> <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-webdav-jackrabbit</artifactId> <version>1.0-beta-7</version> </extension> </extensions> </build> <distributionManagement> <site> <id>sitedeployment</id> <url>dav:http://127.0.0.1/upload-sites/</url> </site> </distributionManagement> </project> See full error message : D:\workspace-new\mkyong-core>mvn site:deploy [INFO] Scanning …

Read more

How to deploy site with “mvn site-deploy” – WebDAV example

Here’s a guide to show you how to use “mvn site:deploy” to deploy your generated documentation site to server automatically, via WebDAV mechanism. P.S In this article, we are using Apache server 2.x with WebDAV enabled. 1. Enabled WebDAV See this guide to learn how to enable WebDAV access on Apache server 2.x. 2. Configure …

Read more

Integrate Maven with Eclipse via External Tool Configuration

During Eclipse development, it’s not practical to go outside of the Eclipse’s environment and execute Maven command in external console. In this article, we show you how to integrate Maven command with Eclipse IDE, via Eclipse’s “External Tool Configuration“. Normally, this external tool is used to run external command within Eclipse environment, and it works …

Read more

How to deploy Maven based war file to Tomcat

In this tutorial, we will show you how to use Maven-Tomcat plugin to package and deploy a WAR file to Tomcat, both in Tomcat 6 and 7. Libraries used : Maven 3 Tomcat 6.0.37 Tomcat 7.0.53 Tomcat 7 Deploy URL = http://localhost:8080/manager/text Command = mvn tomcat7:deploy Tomcat 6 Deploy URL = http://localhost:8080/manager/ Command = mvn …

Read more

How to generate a documentation site for your Maven based project

In Maven, you can use “mvn site” to generate a documentation site for your project information. mvn site The generated site is under your project “target/site” folder. mvn site example See a list of files generated via “mvn site” command. A sample of documentation page. Note Personally, i do not like this feature much, because …

Read more

How to install your project into Maven local repository

In Maven, you can use “mvn install” to package your project and deploy to local repository automatically, so that other developers can use it. mvn install Note When “install” phase is executed, all above phases “validate“, “compile“, “test“, “package“, “integration-test“, “verify” phase , including the current “install” phase will be executed orderly. Refer to this …

Read more

How to clean project with Maven

In Maven based project, many cached output existed in your “target” folder. When you want to build your project for deployment, you have to make sure clean all the cached output so that you are always get the latest for deployment. To clean your project cached output, issue this command : mvn clean See output… …

Read more

How to build project with Maven

To build a Maven based project, open your console, change to your project folder where pom.xml file is placed, and issue this command : mvn package This will execute the Maven “package” phase. Maven build lifecycle Maven is run by phases, read this default Maven build lifecycle article for more detail. So, when the “package” …

Read more

How to display Maven plugin goals and parameters

How do you know what is the available goals of a maven plugin, for example maven-eclipse plugin – mvn eclipse:goals?. In this article, we will show you how to display the entire goals of a Maven plugin. Plugin Documentation The best solution is Googling and visit the plugin documentation, for maven-eclipse, visit this maven-eclipse plugin …

Read more

JDBC Transaction example

JDBC transaction make sure a set of SQL statements is executed as a unit, either all of the statements are executed successfully, or NONE of the statements are executed (rolled back all changes). 1. Without JDBC Transaction 1.1 A JDBC example to insert two rows and update one row. TransactionExample.java package com.mkyong.jdbc; import java.math.BigDecimal; import …

Read more

JDBC Statement – Batch Update

A JDBC Statement example to send a batch of SQL commands (drop,create, insert, update) to the database. BatchUpdate.java package com.mkyong.jdbc.statement; import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.time.LocalDateTime; import java.util.Arrays; public class BatchUpdate { public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); Statement statement = …

Read more

JDBC PreparedStatement – Batch Update

A JDBC PreparedStatement example to send a batch of SQL commands (create, insert, update) to the database. BatchUpdate.java package com.mkyong.jdbc.preparestatement; import java.math.BigDecimal; import java.sql.*; import java.time.LocalDateTime; import java.util.Arrays; public class BatchUpdate { public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); PreparedStatement psDDL = conn.prepareStatement(SQL_CREATE); PreparedStatement psInsert = conn.prepareStatement(SQL_INSERT); PreparedStatement …

Read more

JDBC CallableStatement – Stored Procedure OUT parameter example

A JDBC CallableStatement example to call a stored procedure which accepts IN and OUT parameters. Tested with Java 8 and Oracle database 19c pom.xml <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc</artifactId> <version>8</version> <scope>system</scope> <systemPath>path.to/ojdbc8.jar</systemPath> </dependency> 1. JDBC CallableStatement 1.1 A PL/SQL stored procedure which accepts IN and OUT parameters. CREATE OR REPLACE PROCEDURE get_employee_by_id( p_id IN EMPLOYEE.ID%TYPE, o_name OUT …

Read more

Oracle Stored Procedure SELECT INTO example

Here’s a SELECT INTO stored procedure example in Oracle database. 1. Table SQL Script DBUSER table creation script. CREATE TABLE DBUSER ( USER_ID NUMBER (5) NOT NULL, USERNAME VARCHAR2 (20) NOT NULL, CREATED_BY VARCHAR2 (20) NOT NULL, CREATED_DATE DATE NOT NULL, PRIMARY KEY ( USER_ID ) ) 2. Stored Procedure A stored procedure, uses SELECT …

Read more

JDBC CallableStatement – Stored Procedure CURSOR example

A JDBC CallableStatement example to call a stored procedure which returns a cursor. Tested with Java 8 and Oracle database 19c pom.xml <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc</artifactId> <version>8</version> <scope>system</scope> <systemPath>path.to/ojdbc8.jar</systemPath> </dependency> 1. JDBC CallableStatement 1.1 A PL/SQL stored procedure which returns a cursor. CREATE OR REPLACE PROCEDURE get_employee_by_name( p_name IN EMPLOYEE.NAME%TYPE, o_c_dbuser OUT SYS_REFCURSOR) AS BEGIN OPEN …

Read more

Oracle Stored Procedure Cursor example

Here’s a stored procedure example in Oracle database, using Cursor to manipulate or navigate the records. 1. Table SQL Script DBUSER table creation script. CREATE TABLE DBUSER ( USER_ID NUMBER (5) NOT NULL, USERNAME VARCHAR2 (20) NOT NULL, CREATED_BY VARCHAR2 (20) NOT NULL, CREATED_DATE DATE NOT NULL, PRIMARY KEY ( USER_ID ) ) 2. Stored …

Read more

Oracle Stored Procedure DELETE example

Here’s a DELETE stored procedure example in Oracle database. 1. Table SQL Script DBUSER table creation script. CREATE TABLE DBUSER ( USER_ID NUMBER (5) NOT NULL, USERNAME VARCHAR2 (20) NOT NULL, CREATED_BY VARCHAR2 (20) NOT NULL, CREATED_DATE DATE NOT NULL, PRIMARY KEY ( USER_ID ) ) 2. Stored Procedure A stored procedure, delete the record …

Read more

New Mkyong.com web design ~

Mkyong.com web design is changed ~ Now, it’s more tidy, neat, elegant and optimized for fast loading. Hope you guys like it 🙂 1. Old Mkyong.com Web Design The screenshot of old mkyong.com web design, for my memory … 2. New Mkyong.com Web Design The screenshot of new mkyong.com web design, what you are viewing …

Read more

Oracle Stored Procedure UPDATE example

Here’s an UPDATE stored procedure example in Oracle database. 1. Table SQL Script DBUSER table creation script. CREATE TABLE DBUSER ( USER_ID NUMBER (5) NOT NULL, USERNAME VARCHAR2 (20) NOT NULL, CREATED_BY VARCHAR2 (20) NOT NULL, CREATED_DATE DATE NOT NULL, PRIMARY KEY ( USER_ID ) ) 2. Stored Procedure A stored procedure, accept 2 IN …

Read more

JDBC CallableStatement – Stored Procedure IN parameter example

A JDBC CallableStatement example to call a stored procedure which accepts IN parameters. Tested with Java 8 and Oracle database 19c pom.xml <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc</artifactId> <version>8</version> <scope>system</scope> <systemPath>path.to/ojdbc8.jar</systemPath> </dependency> 1. JDBC CallableStatement 1.1 A PL/SQL stored procedure to insert a row. CREATE OR REPLACE PROCEDURE insert_employee( p_name IN EMPLOYEE.NAME%TYPE, p_salary IN EMPLOYEE.SALARY%TYPE, p_date IN EMPLOYEE.CREATED_DATE%TYPE) …

Read more

Oracle Stored Procedure INSERT example

Here’s an INSERT stored procedure example in Oracle database. 1. Table SQL Script DBUSER table creation script. CREATE TABLE DBUSER ( USER_ID NUMBER (5) NOT NULL, USERNAME VARCHAR2 (20) NOT NULL, CREATED_BY VARCHAR2 (20) NOT NULL, CREATED_DATE DATE NOT NULL, PRIMARY KEY ( USER_ID ) ) 2. Stored Procedure A stored procedure, accept 4 IN …

Read more

Insert date value in PreparedStatement

Problem A simple table script in Oracle database. CREATE TABLE DBUSER ( USER_ID NUMBER (5) NOT NULL, USERNAME VARCHAR2 (20) NOT NULL, CREATED_BY VARCHAR2 (20) NOT NULL, CREATED_DATE DATE NOT NULL, PRIMARY KEY ( USER_ID ) ) No idea how to insert current date value, e.g. “04/04/2011” into “CREATED_DATE” field, via JDBC PreparedStatement. String insertTableSQL …

Read more

JDBC PreparedStatement – Delete a row

A JDBC PreparedStatement example to delete a row. RowDelete.java package com.mkyong.jdbc.preparestatement.row; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class RowDelete { private static final String SQL_DELETE = "DELETE FROM EMPLOYEE WHERE NAME=?"; public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); PreparedStatement preparedStatement = conn.prepareStatement(SQL_DELETE)) { preparedStatement.setString(1, "mkyong"); …

Read more

JDBC PreparedStatement – Select list of rows

A JDBC PreparedStatement example to select a list of rows from the database. RowSelect.java package com.mkyong.jdbc.preparestatement.row; import com.mkyong.jdbc.model.Employee; import java.math.BigDecimal; import java.sql.*; public class RowSelect { private static final String SQL_SELECT = "SELECT * FROM EMPLOYEE"; public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); PreparedStatement preparedStatement = conn.prepareStatement(SQL_SELECT)) { …

Read more

Insert timestamp value in PreparedStatement

Problem A simple table script in Oracle database. CREATE TABLE DBUSER ( USER_ID NUMBER (5) NOT NULL, USERNAME VARCHAR2 (20) NOT NULL, CREATED_BY VARCHAR2 (20) NOT NULL, CREATED_DATE DATE NOT NULL, PRIMARY KEY ( USER_ID ) ) No idea how to insert a timestamp value, e.g. “04/04/2011 14:45:04” into “CREATED_DATE” field, via JDBC PreparedStatement. String …

Read more

JDBC PreparedStatement – Update a row

A JDBC PreparedStatement example to update a row. RowUpdate.java package com.mkyong.jdbc.preparestatement.row; import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class RowUpdate { private static final String SQL_UPDATE = "UPDATE EMPLOYEE SET SALARY=? WHERE NAME=?"; public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); PreparedStatement preparedStatement = conn.prepareStatement(SQL_UPDATE)) …

Read more

JDBC PreparedStatement – Insert a row

A JDBC PreparedStatement example to insert a row into the database. RowInsert.java package com.mkyong.jdbc.preparestatement.row; import java.math.BigDecimal; import java.sql.*; import java.time.LocalDateTime; public class RowInsert { private static final String SQL_INSERT = "INSERT INTO EMPLOYEE (NAME, SALARY, CREATED_DATE) VALUES (?,?,?)"; public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); PreparedStatement preparedStatement = …

Read more

JDBC PreparedStatement – Create a table

A JDBC PreparedStatement example to create a table in the database. CREATE TABLE EMPLOYEE ( ID serial, NAME varchar(100) NOT NULL, SALARY numeric(15, 2) NOT NULL, CREATED_DATE timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP PRIMARY KEY (ID) ); TableCreate.java package com.mkyong.jdbc.preparestatement.table; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class TableCreate { private …

Read more

Oracle Stored Procedures Hello World Examples

List of quick examples to create stored procedures (IN, OUT, IN OUT and Cursor parameter) in Oracle database. PL/SQL code is self-explanatory. 1. Hello World A stored procedure to print out a “Hello World” via DBMS_OUTPUT. CREATE OR REPLACE PROCEDURE procPrintHelloWorld IS BEGIN DBMS_OUTPUT.PUT_LINE(‘Hello World!’); END; / Run it exec procPrintHelloWorld; Output Hello World! 2. …

Read more

JDBC Statement – Select list of rows

A JDBC Statement example to select a list of rows from the database. RowSelect.java package com.mkyong.jdbc.statement.row; import com.mkyong.jdbc.model.Employee; import java.math.BigDecimal; import java.sql.*; public class RowSelect { public static void main(String[] args) { String sql = "SELECT * FROM EMPLOYEE"; try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); Statement statement = conn.createStatement()) { ResultSet resultSet = …

Read more

JDBC Statement – Delete a row

A JDBC Statement example to delete a row. RowDelete.java package com.mkyong.jdbc.statement.row; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class RowDelete { public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); Statement statement = conn.createStatement()) { int row = statement.executeUpdate(deleteByName("mkyong")); // rows affected System.out.println(row); } catch (SQLException e) { …

Read more

JDBC Statement – Update a row

A JDBC Statement example to update a row. RowUpdate.java package com.mkyong.jdbc.statement.row; import java.math.BigDecimal; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class RowUpdate { public static void main(String[] args) { try (Connection conn = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", "postgres", "password"); Statement statement = conn.createStatement()) { int row = statement.executeUpdate(updateSalaryByName("mkyong", new BigDecimal(1080))); // rows affected System.out.println(row); } …

Read more