#Creating tables in Sqlite with Java 8
14 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @modern spruce! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
I can see that stmt is null but how is conn.createStatement() returning null if the connection is not null?
<@&765578700724371486>
How did it close? Did I not open it here
try (Connection conn = DriverManager.getConnection(url)) {
if (conn != null) {
DatabaseMetaData meta = conn.getMetaData();
this.conn = conn;
} else{
Util.tellConsole("Conn is null");
}
} catch (SQLException e) {
Util.tellConsole(e.getMessage());
try closes the resource once the end of the try-block is reached
try (Connection conn = DriverManager.getConnection(url)) {
if (conn != null) {
DatabaseMetaData meta = conn.getMetaData();
this.conn = conn;
} else{
Util.tellConsole("Conn is null");
}
} //CLOSED HERE
catch (SQLException e) {
Util.tellConsole(e.getMessage());
Ahh, I see I was not aware of that. Thank you.
don't use a try with resources statement
public Connection getDBConnection() {
String url = "jdbc:sqlite:HarvHoe.db";
try {
Connection conn = DriverManager.getConnection(url)
if (conn != null) {
return conn;
} else{
Util.tellConsole("Conn is null");
}
} catch (SQLException e) {
Util.tellConsole(e.getMessage();
}
return null;
}
but you need to make sure you are closing the Connection once you are finished
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.