simple database connection using jdbc for kotlin, in conjunction with a spring boot API

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












Database utility object to control access into the database, method used in API call.



package data

import controllers.Person
import java.io.File
import java.io.InputStream
import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement

object DBUtil
private val USER_DIR: String = System.getProperty("user.dir")
private val DB_URL = "jdbc:sqlite:$USER_DIR/SQL/myDB.db"
private const val insertPerson = "INSERT INTO people(age,name,nationality) VALUES(?,?,?)"

fun initDB()
val input: InputStream = File("$USER_DIR/SQL/people.sql").inputStream()
val tableCommand: String = input.bufferedReader().use it.readText()
val conn = makeConnection(DB_URL)
val statement = conn.createStatement()
statement.execute(tableCommand)


fun insertPersonToDB(person : Person)
val conn: Connection = makeConnection(DB_URL)
val ps : PreparedStatement = conn.prepareStatement(insertPerson)
ps.setInt(1, person.age)
ps.setString(2, person.name)
ps.setString(3, person.nationality)
ps.executeUpdate()


private fun makeConnection(url: String) : Connection
return DriverManager.getConnection(url)




And is this an acceptable way to use data classes to serialise and de-serialise json objects?



data class Person @JsonCreator constructor(
@JsonProperty("age")
val age: Int,
@JsonProperty("name")
val name: String,
@JsonProperty("nationality")
val nationality: String,
@JsonProperty("pets")
val pets: Pets
)

data class Pets @JsonCreator constructor(
@JsonProperty("name")
val name: String,

@JsonProperty("breed")
val breedId: Int
)


(whole proj- although was told not to post this https://github.com/343LovingGrace/KotlinToyAPI)







share|improve this question

















  • 2




    I should've said: In addition to a link, the link's fine. Hope you get some good reviews.
    – ferada
    Jul 31 at 20:57
















up vote
0
down vote

favorite












Database utility object to control access into the database, method used in API call.



package data

import controllers.Person
import java.io.File
import java.io.InputStream
import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement

object DBUtil
private val USER_DIR: String = System.getProperty("user.dir")
private val DB_URL = "jdbc:sqlite:$USER_DIR/SQL/myDB.db"
private const val insertPerson = "INSERT INTO people(age,name,nationality) VALUES(?,?,?)"

fun initDB()
val input: InputStream = File("$USER_DIR/SQL/people.sql").inputStream()
val tableCommand: String = input.bufferedReader().use it.readText()
val conn = makeConnection(DB_URL)
val statement = conn.createStatement()
statement.execute(tableCommand)


fun insertPersonToDB(person : Person)
val conn: Connection = makeConnection(DB_URL)
val ps : PreparedStatement = conn.prepareStatement(insertPerson)
ps.setInt(1, person.age)
ps.setString(2, person.name)
ps.setString(3, person.nationality)
ps.executeUpdate()


private fun makeConnection(url: String) : Connection
return DriverManager.getConnection(url)




And is this an acceptable way to use data classes to serialise and de-serialise json objects?



data class Person @JsonCreator constructor(
@JsonProperty("age")
val age: Int,
@JsonProperty("name")
val name: String,
@JsonProperty("nationality")
val nationality: String,
@JsonProperty("pets")
val pets: Pets
)

data class Pets @JsonCreator constructor(
@JsonProperty("name")
val name: String,

@JsonProperty("breed")
val breedId: Int
)


(whole proj- although was told not to post this https://github.com/343LovingGrace/KotlinToyAPI)







share|improve this question

















  • 2




    I should've said: In addition to a link, the link's fine. Hope you get some good reviews.
    – ferada
    Jul 31 at 20:57












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Database utility object to control access into the database, method used in API call.



package data

import controllers.Person
import java.io.File
import java.io.InputStream
import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement

object DBUtil
private val USER_DIR: String = System.getProperty("user.dir")
private val DB_URL = "jdbc:sqlite:$USER_DIR/SQL/myDB.db"
private const val insertPerson = "INSERT INTO people(age,name,nationality) VALUES(?,?,?)"

fun initDB()
val input: InputStream = File("$USER_DIR/SQL/people.sql").inputStream()
val tableCommand: String = input.bufferedReader().use it.readText()
val conn = makeConnection(DB_URL)
val statement = conn.createStatement()
statement.execute(tableCommand)


fun insertPersonToDB(person : Person)
val conn: Connection = makeConnection(DB_URL)
val ps : PreparedStatement = conn.prepareStatement(insertPerson)
ps.setInt(1, person.age)
ps.setString(2, person.name)
ps.setString(3, person.nationality)
ps.executeUpdate()


private fun makeConnection(url: String) : Connection
return DriverManager.getConnection(url)




And is this an acceptable way to use data classes to serialise and de-serialise json objects?



data class Person @JsonCreator constructor(
@JsonProperty("age")
val age: Int,
@JsonProperty("name")
val name: String,
@JsonProperty("nationality")
val nationality: String,
@JsonProperty("pets")
val pets: Pets
)

data class Pets @JsonCreator constructor(
@JsonProperty("name")
val name: String,

@JsonProperty("breed")
val breedId: Int
)


(whole proj- although was told not to post this https://github.com/343LovingGrace/KotlinToyAPI)







share|improve this question













Database utility object to control access into the database, method used in API call.



package data

import controllers.Person
import java.io.File
import java.io.InputStream
import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement

object DBUtil
private val USER_DIR: String = System.getProperty("user.dir")
private val DB_URL = "jdbc:sqlite:$USER_DIR/SQL/myDB.db"
private const val insertPerson = "INSERT INTO people(age,name,nationality) VALUES(?,?,?)"

fun initDB()
val input: InputStream = File("$USER_DIR/SQL/people.sql").inputStream()
val tableCommand: String = input.bufferedReader().use it.readText()
val conn = makeConnection(DB_URL)
val statement = conn.createStatement()
statement.execute(tableCommand)


fun insertPersonToDB(person : Person)
val conn: Connection = makeConnection(DB_URL)
val ps : PreparedStatement = conn.prepareStatement(insertPerson)
ps.setInt(1, person.age)
ps.setString(2, person.name)
ps.setString(3, person.nationality)
ps.executeUpdate()


private fun makeConnection(url: String) : Connection
return DriverManager.getConnection(url)




And is this an acceptable way to use data classes to serialise and de-serialise json objects?



data class Person @JsonCreator constructor(
@JsonProperty("age")
val age: Int,
@JsonProperty("name")
val name: String,
@JsonProperty("nationality")
val nationality: String,
@JsonProperty("pets")
val pets: Pets
)

data class Pets @JsonCreator constructor(
@JsonProperty("name")
val name: String,

@JsonProperty("breed")
val breedId: Int
)


(whole proj- although was told not to post this https://github.com/343LovingGrace/KotlinToyAPI)









share|improve this question












share|improve this question




share|improve this question








edited Jul 31 at 19:45
























asked Jul 31 at 18:12









jimmy_jazz

272




272







  • 2




    I should've said: In addition to a link, the link's fine. Hope you get some good reviews.
    – ferada
    Jul 31 at 20:57












  • 2




    I should've said: In addition to a link, the link's fine. Hope you get some good reviews.
    – ferada
    Jul 31 at 20:57







2




2




I should've said: In addition to a link, the link's fine. Hope you get some good reviews.
– ferada
Jul 31 at 20:57




I should've said: In addition to a link, the link's fine. Hope you get some good reviews.
– ferada
Jul 31 at 20:57















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f200685%2fsimple-database-connection-using-jdbc-for-kotlin-in-conjunction-with-a-spring-b%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f200685%2fsimple-database-connection-using-jdbc-for-kotlin-in-conjunction-with-a-spring-b%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation