BAEL-5058 : apache-derby added to dir (#11339)

* BAEL-5058 : apache-derby added to dir

* BAEL-5058 : apache-derby fixed changes

* BAEL-5058 : apache-derby parent pom fixed
This commit is contained in:
Arash Ariani 2021-10-28 07:55:34 +03:30 committed by GitHub
parent b9fadd8f3d
commit 7ab19421e3
3 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>persistence-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apache-derby</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.13.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.derby/derbyclient -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.13.1.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,39 @@
package com.baeldung.derby;
import java.sql.*;
/**
* Created by arash on 14.10.21.
*/
public class DerbyApplicationDemo {
public static void main(String[] args) {
runner("jdbc:derby:baeldung;create=true");
}
private static void runner(String urlConnection) {
try {
Connection con = DriverManager.getConnection(urlConnection);
Statement statement = con.createStatement();
if (!isTableExists("authors", con)) {
String createSQL = "CREATE TABLE authors (id INT PRIMARY KEY,first_name VARCHAR(255),last_name VARCHAR(255))";
statement.execute(createSQL);
String insertSQL = "INSERT INTO authors VALUES (1, 'arash','ariani')";
statement.execute(insertSQL);
}
String selectSQL = "SELECT * FROM authors";
ResultSet result = statement.executeQuery(selectSQL);
while (result.next()) {
// use result here
}
} catch (SQLException e) {
e.printStackTrace();
}
}
private static boolean isTableExists(String tableName, Connection connection) throws SQLException {
DatabaseMetaData meta = connection.getMetaData();
ResultSet result = meta.getTables(null, null, tableName.toUpperCase(), null);
return result.next();
}
}

View File

@ -17,6 +17,7 @@
<module>activejdbc</module>
<module>apache-bookkeeper</module><!-- BAEL-2322 -->
<module>apache-cayenne</module>
<module>apache-derby</module>
<module>core-java-persistence</module>
<module>core-java-persistence-2</module>
<module>deltaspike</module>