From ae37a7b1cfdfa8261d9119e6c1376ce96d0fee59 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 27 Sep 2025 17:06:36 -0600 Subject: [PATCH] Adding in example JDBC connection set up, and db connection use with ResourceBundle to hide credentials --- .gitignore | 1 + cs-115-jdbc/.idea/dbnavigator.xml | 575 ++++++++++++++++++++++++++++++ cs-115-jdbc/.idea/vcs.xml | 6 + cs-115-jdbc/cs-115-jdbc.iml | 9 + cs-115-jdbc/src/Main.java | 28 +- 5 files changed, 617 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 cs-115-jdbc/.idea/dbnavigator.xml create mode 100644 cs-115-jdbc/.idea/vcs.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51f5037 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dbconfig.properties diff --git a/cs-115-jdbc/.idea/dbnavigator.xml b/cs-115-jdbc/.idea/dbnavigator.xml new file mode 100644 index 0000000..8630698 --- /dev/null +++ b/cs-115-jdbc/.idea/dbnavigator.xml @@ -0,0 +1,575 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/cs-115-jdbc/.idea/vcs.xml b/cs-115-jdbc/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/cs-115-jdbc/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cs-115-jdbc/cs-115-jdbc.iml b/cs-115-jdbc/cs-115-jdbc.iml index c90834f..1a18385 100644 --- a/cs-115-jdbc/cs-115-jdbc.iml +++ b/cs-115-jdbc/cs-115-jdbc.iml @@ -7,5 +7,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/cs-115-jdbc/src/Main.java b/cs-115-jdbc/src/Main.java index f5858db..2a1c80b 100644 --- a/cs-115-jdbc/src/Main.java +++ b/cs-115-jdbc/src/Main.java @@ -1,5 +1,29 @@ -public class Main { - public static void main(String[] args) { +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Connection; +import java.util.ResourceBundle; +public class Main { + + public static void main(String[] args) { + getConnection(); + } + + protected static Connection getConnection() { + Connection connection = null; + + try { + ResourceBundle reader = ResourceBundle.getBundle("dbconfig"); + Class.forName(reader.getString("db.driver")); + connection = DriverManager.getConnection(reader.getString("db.url"), reader.getString("db.username"), reader.getString("db.password")); + return connection; + } catch (SQLException exception) { + System.out.println("ExceptionMessage: " + exception.getMessage()); + System.out.println("ErrorCode: " + exception.getErrorCode()); + return null; + } catch (Exception exception) { + System.out.println("ExceptionMessage: " + exception.getMessage()); + return null; + } } } \ No newline at end of file