Skip to content

Commit e01ec6b

Browse files
committed
project created
and db connection property added
1 parent 5e9f9dc commit e01ec6b

8 files changed

Lines changed: 227 additions & 0 deletions

File tree

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
db-example/.idea/compiler.xml
3+
db-example/.idea/misc.xml
4+
db-example/.idea/workspace.xml
5+
db-example/db-example.iml
6+
db-example/target/classes/config/DbConnectionConfig.class
7+
db-example/target/classes/entity/Employee.class
8+
db-example/target/classes/Main.class
9+
db-example/target/classes/print/PrintDbResultSet.class
10+
db-example/target/classes/query/InsertQueryApi.class
11+
db-example/target/classes/query/SelectQueryApi.class

db-example/pom.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>db-example</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<mysql.version>5.1.48</mysql.version>
13+
</properties>
14+
<dependencies>
15+
<dependency>
16+
<groupId>mysql</groupId>
17+
<artifactId>mysql-connector-java</artifactId>
18+
<version>${mysql.version}</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.mongodb</groupId>
22+
<artifactId>mongodb-driver</artifactId>
23+
<version>3.4.2</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>log4j</groupId>
27+
<artifactId>log4j</artifactId>
28+
<version>1.2.17</version>
29+
</dependency>
30+
</dependencies>
31+
32+
<repositories>
33+
<repository>
34+
<id>java.net-Public</id>
35+
<name>Maven Java Net Snapshots and Releases</name>
36+
<url>https://maven.java.net/content/groups/public/</url>
37+
</repository>
38+
</repositories>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<version>2.5.1</version>
46+
<configuration>
47+
<source>1.8</source>
48+
<target>1.8</target>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</project>

db-example/src/main/java/Main.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import config.DbConnectionConfig;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.SQLException;
6+
7+
public class Main {
8+
9+
public static void main(String[] args) {
10+
try {
11+
testConnectToDatabase(DbConnectionConfig.getDbHost(), DbConnectionConfig.getDbUsername(), DbConnectionConfig.getDbUserPassword(), DbConnectionConfig.getJdbcDriver());
12+
} catch (SQLException e) {
13+
e.printStackTrace();
14+
}
15+
}
16+
17+
public static void testConnectToDatabase(String dbHost, String dbUser, String dbPassword, String jdbc) throws SQLException {
18+
Connection dbConnecttion = null;
19+
try {
20+
Class.forName(jdbc);
21+
dbConnecttion = DriverManager.getConnection(dbHost, dbUser, dbPassword);
22+
23+
if (dbConnecttion != null) {
24+
System.out.println("Veritabanına baglanıldı");
25+
dbConnecttion.close();
26+
} else {
27+
System.out.println("Veritabanına erişim hatalı");
28+
}
29+
30+
} catch (Exception e) {
31+
e.printStackTrace();
32+
} finally {
33+
if (dbConnecttion != null) {
34+
dbConnecttion.close();
35+
}
36+
}
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package config;
2+
3+
public class DbConnectionConfig {
4+
5+
private final static String DB_HOST = "jdbc:mysql://remotemysql.com:3306/BiEfcKCYFs?useSSL=false";
6+
private final static String DB_USERNAME = "BiEfcKCYFs";
7+
private final static String DB_USER_PASSWORD = "iVm6eDkLab";
8+
private final static String JDBC_DRIVER = "com.mysql.jdbc.Driver";
9+
10+
public static String getDbHost() {
11+
return DB_HOST;
12+
}
13+
14+
public static String getDbUsername() {
15+
return DB_USERNAME;
16+
}
17+
18+
public static String getDbUserPassword() {
19+
return DB_USER_PASSWORD;
20+
}
21+
22+
public static String getJdbcDriver() {
23+
return JDBC_DRIVER;
24+
}
25+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package entity;
2+
3+
import java.util.Date;
4+
5+
public class Employee {
6+
7+
private Long id;
8+
private String name;
9+
private String lastName;
10+
private String gender;
11+
private Date birthDate;
12+
private Date hireDate;
13+
14+
public String getName() {
15+
return name;
16+
}
17+
18+
public void setName(String name) {
19+
this.name = name;
20+
}
21+
22+
public String getLastName() {
23+
return lastName;
24+
}
25+
26+
public void setLastName(String lastName) {
27+
this.lastName = lastName;
28+
}
29+
30+
public String getGender() {
31+
return gender;
32+
}
33+
34+
public void setGender(String gender) {
35+
this.gender = gender;
36+
}
37+
38+
public Date getBirthDate() {
39+
return birthDate;
40+
}
41+
42+
public void setBirthDate(Date birthDate) {
43+
this.birthDate = birthDate;
44+
}
45+
46+
public Date getHireDate() {
47+
return hireDate;
48+
}
49+
50+
public void setHireDate(Date hireDate) {
51+
this.hireDate = hireDate;
52+
}
53+
54+
@Override
55+
public String toString() {
56+
return "Employee{" +
57+
"id=" + id +
58+
", name='" + name + '\'' +
59+
", lastName='" + lastName + '\'' +
60+
", gender='" + gender + '\'' +
61+
", birthDate=" + birthDate +
62+
", hireDate=" + hireDate +
63+
'}';
64+
}
65+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package print;
2+
3+
import java.sql.ResultSet;
4+
import java.sql.SQLException;
5+
6+
public class PrintDbResultSet {
7+
8+
public static void printEmployeeFormattedText(ResultSet resultSet) throws SQLException {
9+
10+
StringBuilder builder = new StringBuilder();
11+
builder.append("Record - " + resultSet.getRow());
12+
builder.append(" ====> ");
13+
builder.append(resultSet.getLong("emp_no"));
14+
builder.append(" ");
15+
builder.append(resultSet.getString("first_name"));
16+
builder.append(" ");
17+
builder.append(resultSet.getString("last_name"));
18+
builder.append(" ");
19+
builder.append(resultSet.getString("gender"));
20+
builder.append(" ");
21+
builder.append(resultSet.getDate("birth_date"));
22+
builder.append(" ");
23+
builder.append(resultSet.getDate("hire_date"));
24+
builder.append(" ");
25+
System.out.println(builder.toString());
26+
}
27+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package query;
2+
3+
public class InsertQueryApi {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package query;
2+
3+
public class SelectQueryApi {
4+
}

0 commit comments

Comments
 (0)