Skip to content

Commit eaedcf5

Browse files
author
Pankaj Kumar
committed
HSQLDB Java Example
1 parent 4662b6c commit eaedcf5

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

HSQLDB-Example/pom.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.journaldev.hsqldb</groupId>
6+
<artifactId>HSQLDB-Example</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>org.hsqldb</groupId>
12+
<artifactId>hsqldb</artifactId>
13+
<version>2.4.1</version>
14+
</dependency>
15+
</dependencies>
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<artifactId>maven-compiler-plugin</artifactId>
20+
<version>3.7.0</version>
21+
<configuration>
22+
<release>10</release>
23+
</configuration>
24+
</plugin>
25+
</plugins>
26+
</build>
27+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.journaldev.hsqldb;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.SQLException;
6+
7+
public class HSQLDBConnection {
8+
9+
public static Connection getConnection() {
10+
Connection con = null;
11+
12+
try {
13+
Class.forName("org.hsqldb.jdbc.JDBCDriver");
14+
System.out.println("HSQLDB JDBCDriver Loaded");
15+
con = DriverManager.getConnection(
16+
"jdbc:hsqldb:hsql://localhost/Test", "SA", "");
17+
System.out.println("HSQLDB Connection Created");
18+
} catch (ClassNotFoundException e) {
19+
e.printStackTrace();
20+
} catch (SQLException e) {
21+
e.printStackTrace();
22+
}
23+
return con;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.journaldev.hsqldb;
2+
3+
import java.sql.Connection;
4+
import java.sql.PreparedStatement;
5+
import java.sql.ResultSet;
6+
import java.sql.SQLException;
7+
8+
public class HSQLDBExample {
9+
10+
public static void main(String[] args) {
11+
Connection con = HSQLDBConnection.getConnection();
12+
System.out.println("Connection Obtained");
13+
14+
try {
15+
PreparedStatement ps = con.prepareStatement(
16+
"select id, firstName, lastName from customer");
17+
ResultSet rs = ps.executeQuery();
18+
while (rs.next()) {
19+
System.out.println("ID = " + rs.getInt("id") +
20+
", Name = " + rs.getString("firstName") + " "
21+
+ rs.getString("lastName"));
22+
}
23+
rs.close();
24+
con.close();
25+
} catch (SQLException e1) {
26+
e1.printStackTrace();
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)