-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit to fetch all the information from the database.
Included a zonedDate conversion Removed all test at the moment
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |