simple database connection using jdbc for kotlin, in conjunction with a spring boot API
Clash 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)
rest sqlite kotlin jdbc
add a comment |Â
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)
rest sqlite kotlin jdbc
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
add a comment |Â
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)
rest sqlite kotlin jdbc
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)
rest sqlite kotlin jdbc
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
add a comment |Â
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
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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