Skip to content

Commit

Permalink
Initial commit to fetch all the information from the database.
Browse files Browse the repository at this point in the history
Included a zonedDate conversion
Removed all test at the moment
  • Loading branch information
Lei-Tin authored and ScottCTD committed Nov 6, 2022
1 parent 3594fc3 commit 91db0a1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ repositories {
dependencies {
implementation 'junit:junit:4.13.1'
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0')

// https://mvnrepository.com/artifact/mysql/mysql-connector-java
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.31'
}

test {
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/billgates/Connector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package billgates;

import java.sql.*;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class Connector {

public static void main(String[] args) {
try {
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/bill",
"root",
"");

Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery("SELECT * FROM bill1");

while (resultSet.next()) {
// Note that, aside from the general types that we have here
// All the rest objects will be parsed in a string format
int entryId = resultSet.getInt("entry_id");
double value = resultSet.getDouble("value");
Timestamp date = resultSet.getTimestamp("date");
String currency = resultSet.getString("currency");
String description = resultSet.getString("description");
String from = resultSet.getString("from");
String to = resultSet.getString("to");
String location = resultSet.getString("location");

Instant i = Instant.ofEpochMilli(date.getTime());

// We can pass in the different zones we want to convert in, and we can obtain the value we want
ZonedDateTime zonedDate = ZonedDateTime.ofInstant(i, ZoneId.of("US/Eastern"));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
8 changes: 8 additions & 0 deletions src/test/java/billgates/ConnectorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package billgates;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class ConnectorTest {

}

0 comments on commit 91db0a1

Please sign in to comment.