Database is locked in SQLite [Java]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















updated



try
{
sqlite.setDbPath(dbPath);
con = sqlite.connect();
if(!con.isClosed())
{
String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"'"; // and Password='"+password+"'";
ResultSet rs = con.createStatement().executeQuery(query);
while(rs.next())
{
if(rs.getString("Username").equals(username))//confronto se Username è gia esistente
{
trovato = true;
risultato = "gia' presente";
}
}

if(trovato==false) {
createUsers(username,password,name,surname,email,appname,ip,authorized,token);
risultato="inserito";
}

if(con!=null)
{
con.close();
}
if(sqlite != null)
{
sqlite.close();
}
if(rs != null)
{
rs.close();
}
}


In try catch block I've open connection with database embedded but in first time i don't close all connection..
With if control the program close all open connection and works well










share|improve this question

























  • Do you have your database opened in some sql editor? That'll probably cause an error like that.

    – Mark
    Jan 3 at 11:21













  • I try to close sqleditor but i've the same problem

    – luca pellegrini
    Jan 3 at 11:26











  • IIRC SQLite only allows a single connection to the database, so if you have multiple connections it will fail. This may be a limitation of older versions though, so in that case you may need to upgrade the sqlite version you're using. That said, in my opinion, SQLite is not really a suitable database for a web application.

    – Mark Rotteveel
    Jan 3 at 14:13











  • Your current code has a lot of potential resource leaks. I'd suggest that you rewrite your code to use try-with-resources, it will simplify things a lot and reduce the complexity of your code.

    – Mark Rotteveel
    Jan 3 at 14:15











  • BTW: con.createStatement().close(); makes zero sense. You don't need to create a statement if you're going to immediately close it.

    – Mark Rotteveel
    Jan 3 at 14:16


















1















updated



try
{
sqlite.setDbPath(dbPath);
con = sqlite.connect();
if(!con.isClosed())
{
String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"'"; // and Password='"+password+"'";
ResultSet rs = con.createStatement().executeQuery(query);
while(rs.next())
{
if(rs.getString("Username").equals(username))//confronto se Username è gia esistente
{
trovato = true;
risultato = "gia' presente";
}
}

if(trovato==false) {
createUsers(username,password,name,surname,email,appname,ip,authorized,token);
risultato="inserito";
}

if(con!=null)
{
con.close();
}
if(sqlite != null)
{
sqlite.close();
}
if(rs != null)
{
rs.close();
}
}


In try catch block I've open connection with database embedded but in first time i don't close all connection..
With if control the program close all open connection and works well










share|improve this question

























  • Do you have your database opened in some sql editor? That'll probably cause an error like that.

    – Mark
    Jan 3 at 11:21













  • I try to close sqleditor but i've the same problem

    – luca pellegrini
    Jan 3 at 11:26











  • IIRC SQLite only allows a single connection to the database, so if you have multiple connections it will fail. This may be a limitation of older versions though, so in that case you may need to upgrade the sqlite version you're using. That said, in my opinion, SQLite is not really a suitable database for a web application.

    – Mark Rotteveel
    Jan 3 at 14:13











  • Your current code has a lot of potential resource leaks. I'd suggest that you rewrite your code to use try-with-resources, it will simplify things a lot and reduce the complexity of your code.

    – Mark Rotteveel
    Jan 3 at 14:15











  • BTW: con.createStatement().close(); makes zero sense. You don't need to create a statement if you're going to immediately close it.

    – Mark Rotteveel
    Jan 3 at 14:16














1












1








1








updated



try
{
sqlite.setDbPath(dbPath);
con = sqlite.connect();
if(!con.isClosed())
{
String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"'"; // and Password='"+password+"'";
ResultSet rs = con.createStatement().executeQuery(query);
while(rs.next())
{
if(rs.getString("Username").equals(username))//confronto se Username è gia esistente
{
trovato = true;
risultato = "gia' presente";
}
}

if(trovato==false) {
createUsers(username,password,name,surname,email,appname,ip,authorized,token);
risultato="inserito";
}

if(con!=null)
{
con.close();
}
if(sqlite != null)
{
sqlite.close();
}
if(rs != null)
{
rs.close();
}
}


In try catch block I've open connection with database embedded but in first time i don't close all connection..
With if control the program close all open connection and works well










share|improve this question
















updated



try
{
sqlite.setDbPath(dbPath);
con = sqlite.connect();
if(!con.isClosed())
{
String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"'"; // and Password='"+password+"'";
ResultSet rs = con.createStatement().executeQuery(query);
while(rs.next())
{
if(rs.getString("Username").equals(username))//confronto se Username è gia esistente
{
trovato = true;
risultato = "gia' presente";
}
}

if(trovato==false) {
createUsers(username,password,name,surname,email,appname,ip,authorized,token);
risultato="inserito";
}

if(con!=null)
{
con.close();
}
if(sqlite != null)
{
sqlite.close();
}
if(rs != null)
{
rs.close();
}
}


In try catch block I've open connection with database embedded but in first time i don't close all connection..
With if control the program close all open connection and works well







java database sqlite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 16:30







luca pellegrini

















asked Jan 3 at 11:20









luca pellegriniluca pellegrini

428




428













  • Do you have your database opened in some sql editor? That'll probably cause an error like that.

    – Mark
    Jan 3 at 11:21













  • I try to close sqleditor but i've the same problem

    – luca pellegrini
    Jan 3 at 11:26











  • IIRC SQLite only allows a single connection to the database, so if you have multiple connections it will fail. This may be a limitation of older versions though, so in that case you may need to upgrade the sqlite version you're using. That said, in my opinion, SQLite is not really a suitable database for a web application.

    – Mark Rotteveel
    Jan 3 at 14:13











  • Your current code has a lot of potential resource leaks. I'd suggest that you rewrite your code to use try-with-resources, it will simplify things a lot and reduce the complexity of your code.

    – Mark Rotteveel
    Jan 3 at 14:15











  • BTW: con.createStatement().close(); makes zero sense. You don't need to create a statement if you're going to immediately close it.

    – Mark Rotteveel
    Jan 3 at 14:16



















  • Do you have your database opened in some sql editor? That'll probably cause an error like that.

    – Mark
    Jan 3 at 11:21













  • I try to close sqleditor but i've the same problem

    – luca pellegrini
    Jan 3 at 11:26











  • IIRC SQLite only allows a single connection to the database, so if you have multiple connections it will fail. This may be a limitation of older versions though, so in that case you may need to upgrade the sqlite version you're using. That said, in my opinion, SQLite is not really a suitable database for a web application.

    – Mark Rotteveel
    Jan 3 at 14:13











  • Your current code has a lot of potential resource leaks. I'd suggest that you rewrite your code to use try-with-resources, it will simplify things a lot and reduce the complexity of your code.

    – Mark Rotteveel
    Jan 3 at 14:15











  • BTW: con.createStatement().close(); makes zero sense. You don't need to create a statement if you're going to immediately close it.

    – Mark Rotteveel
    Jan 3 at 14:16

















Do you have your database opened in some sql editor? That'll probably cause an error like that.

– Mark
Jan 3 at 11:21







Do you have your database opened in some sql editor? That'll probably cause an error like that.

– Mark
Jan 3 at 11:21















I try to close sqleditor but i've the same problem

– luca pellegrini
Jan 3 at 11:26





I try to close sqleditor but i've the same problem

– luca pellegrini
Jan 3 at 11:26













IIRC SQLite only allows a single connection to the database, so if you have multiple connections it will fail. This may be a limitation of older versions though, so in that case you may need to upgrade the sqlite version you're using. That said, in my opinion, SQLite is not really a suitable database for a web application.

– Mark Rotteveel
Jan 3 at 14:13





IIRC SQLite only allows a single connection to the database, so if you have multiple connections it will fail. This may be a limitation of older versions though, so in that case you may need to upgrade the sqlite version you're using. That said, in my opinion, SQLite is not really a suitable database for a web application.

– Mark Rotteveel
Jan 3 at 14:13













Your current code has a lot of potential resource leaks. I'd suggest that you rewrite your code to use try-with-resources, it will simplify things a lot and reduce the complexity of your code.

– Mark Rotteveel
Jan 3 at 14:15





Your current code has a lot of potential resource leaks. I'd suggest that you rewrite your code to use try-with-resources, it will simplify things a lot and reduce the complexity of your code.

– Mark Rotteveel
Jan 3 at 14:15













BTW: con.createStatement().close(); makes zero sense. You don't need to create a statement if you're going to immediately close it.

– Mark Rotteveel
Jan 3 at 14:16





BTW: con.createStatement().close(); makes zero sense. You don't need to create a statement if you're going to immediately close it.

– Mark Rotteveel
Jan 3 at 14:16












2 Answers
2






active

oldest

votes


















1














Update 2



Here is an abbreviated version using try-with-resource instead. Code is simpler and shorter



public String RegisterUser(... ) {
boolean trovato = false;
int authorized=0;

SqliteConnection sqlite = new SqliteConnection();
String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";
String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"' and Password='"+password+"'";

try (java.sql.Connection con = sqlite.connect();
Statement statement = con.createStatement();
Statement updStatement = con.createStatement();
) {
ResultSet rsActiveServices = con.createStatement().executeQuery(query);
// handle result set as before
} catch(SQLException e) {
e.printStackTrace();
System.out.println("errore" + e);
}
if(trovato==false) {
createUser(username, password, name, surname, appname, email, ip)
}
return "username: " + username;
}


private createUser(String username, String password, String name, String surname, String appname, String email, String ip {
String query1="INSERT INTO Apps (Username,Password,Name,Surname,Email,AppName,Ip,Authorized,Token) VALUES ('" + username + "'," + "'" +password +"','" + name + "','" + surname + "','" +email + "','" + appname + "','"+ip+"','"+authorized+"','"+token+"')";
SqliteConnection sqlite = new SqliteConnection();
String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";

try (java.sql.Connection con = sqlite.connect();
Statement statement = con.createStatement();) {
updStatement.executeUpdate(query1);
} catch(SQLException e) {
e.printStackTrace();
System.out.println("errore" + e);
}
}




It could very well be that your prepared statement isn't properly closed. Change



ResultSet rsActiveServices = con.createStatement().executeQuery(query);


to



statement = con.createStatement();
ResultSet rsActiveServices = statement.executeQuery(query);


where statement is declared before try



java.sql.Connection con = null;
Statement statement = null;


and then close it in your finally clause



finally
{
try
{
statement.close();
con.close();
sqlite.close();
}


Update 1



I just noticed that your are trying to close your objects twice which is wrong, remove the first set of close calls and only close within finally {} at the end.






share|improve this answer


























  • the row of code statement.close(); do error

    – luca pellegrini
    Jan 3 at 13:21











  • finally { try { statement.close(); con.close(); sqlite.close(); } i can't put statement.close(); into finally

    – luca pellegrini
    Jan 3 at 13:34













  • @lucapellegrini, simple mistake by me. You need to declare the variable outside the try clause. I'll update the answer

    – Joakim Danielson
    Jan 3 at 14:08











  • Using try-with-resources is probably better (and shorter).

    – Mark Rotteveel
    Jan 3 at 14:14











  • @MarkRotteveel I know but this felt like the simplest way to move forward.

    – Joakim Danielson
    Jan 3 at 14:27



















0














Resolved



I do errors with open and close connection in Main.. With SQLite the connection you have to open and close everytime it's carried out a query of all type(Insert, Delete,Update ecc..)






share|improve this answer
























    Your Answer






    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: "1"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021317%2fdatabase-is-locked-in-sqlite-java%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Update 2



    Here is an abbreviated version using try-with-resource instead. Code is simpler and shorter



    public String RegisterUser(... ) {
    boolean trovato = false;
    int authorized=0;

    SqliteConnection sqlite = new SqliteConnection();
    String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";
    String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"' and Password='"+password+"'";

    try (java.sql.Connection con = sqlite.connect();
    Statement statement = con.createStatement();
    Statement updStatement = con.createStatement();
    ) {
    ResultSet rsActiveServices = con.createStatement().executeQuery(query);
    // handle result set as before
    } catch(SQLException e) {
    e.printStackTrace();
    System.out.println("errore" + e);
    }
    if(trovato==false) {
    createUser(username, password, name, surname, appname, email, ip)
    }
    return "username: " + username;
    }


    private createUser(String username, String password, String name, String surname, String appname, String email, String ip {
    String query1="INSERT INTO Apps (Username,Password,Name,Surname,Email,AppName,Ip,Authorized,Token) VALUES ('" + username + "'," + "'" +password +"','" + name + "','" + surname + "','" +email + "','" + appname + "','"+ip+"','"+authorized+"','"+token+"')";
    SqliteConnection sqlite = new SqliteConnection();
    String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";

    try (java.sql.Connection con = sqlite.connect();
    Statement statement = con.createStatement();) {
    updStatement.executeUpdate(query1);
    } catch(SQLException e) {
    e.printStackTrace();
    System.out.println("errore" + e);
    }
    }




    It could very well be that your prepared statement isn't properly closed. Change



    ResultSet rsActiveServices = con.createStatement().executeQuery(query);


    to



    statement = con.createStatement();
    ResultSet rsActiveServices = statement.executeQuery(query);


    where statement is declared before try



    java.sql.Connection con = null;
    Statement statement = null;


    and then close it in your finally clause



    finally
    {
    try
    {
    statement.close();
    con.close();
    sqlite.close();
    }


    Update 1



    I just noticed that your are trying to close your objects twice which is wrong, remove the first set of close calls and only close within finally {} at the end.






    share|improve this answer


























    • the row of code statement.close(); do error

      – luca pellegrini
      Jan 3 at 13:21











    • finally { try { statement.close(); con.close(); sqlite.close(); } i can't put statement.close(); into finally

      – luca pellegrini
      Jan 3 at 13:34













    • @lucapellegrini, simple mistake by me. You need to declare the variable outside the try clause. I'll update the answer

      – Joakim Danielson
      Jan 3 at 14:08











    • Using try-with-resources is probably better (and shorter).

      – Mark Rotteveel
      Jan 3 at 14:14











    • @MarkRotteveel I know but this felt like the simplest way to move forward.

      – Joakim Danielson
      Jan 3 at 14:27
















    1














    Update 2



    Here is an abbreviated version using try-with-resource instead. Code is simpler and shorter



    public String RegisterUser(... ) {
    boolean trovato = false;
    int authorized=0;

    SqliteConnection sqlite = new SqliteConnection();
    String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";
    String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"' and Password='"+password+"'";

    try (java.sql.Connection con = sqlite.connect();
    Statement statement = con.createStatement();
    Statement updStatement = con.createStatement();
    ) {
    ResultSet rsActiveServices = con.createStatement().executeQuery(query);
    // handle result set as before
    } catch(SQLException e) {
    e.printStackTrace();
    System.out.println("errore" + e);
    }
    if(trovato==false) {
    createUser(username, password, name, surname, appname, email, ip)
    }
    return "username: " + username;
    }


    private createUser(String username, String password, String name, String surname, String appname, String email, String ip {
    String query1="INSERT INTO Apps (Username,Password,Name,Surname,Email,AppName,Ip,Authorized,Token) VALUES ('" + username + "'," + "'" +password +"','" + name + "','" + surname + "','" +email + "','" + appname + "','"+ip+"','"+authorized+"','"+token+"')";
    SqliteConnection sqlite = new SqliteConnection();
    String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";

    try (java.sql.Connection con = sqlite.connect();
    Statement statement = con.createStatement();) {
    updStatement.executeUpdate(query1);
    } catch(SQLException e) {
    e.printStackTrace();
    System.out.println("errore" + e);
    }
    }




    It could very well be that your prepared statement isn't properly closed. Change



    ResultSet rsActiveServices = con.createStatement().executeQuery(query);


    to



    statement = con.createStatement();
    ResultSet rsActiveServices = statement.executeQuery(query);


    where statement is declared before try



    java.sql.Connection con = null;
    Statement statement = null;


    and then close it in your finally clause



    finally
    {
    try
    {
    statement.close();
    con.close();
    sqlite.close();
    }


    Update 1



    I just noticed that your are trying to close your objects twice which is wrong, remove the first set of close calls and only close within finally {} at the end.






    share|improve this answer


























    • the row of code statement.close(); do error

      – luca pellegrini
      Jan 3 at 13:21











    • finally { try { statement.close(); con.close(); sqlite.close(); } i can't put statement.close(); into finally

      – luca pellegrini
      Jan 3 at 13:34













    • @lucapellegrini, simple mistake by me. You need to declare the variable outside the try clause. I'll update the answer

      – Joakim Danielson
      Jan 3 at 14:08











    • Using try-with-resources is probably better (and shorter).

      – Mark Rotteveel
      Jan 3 at 14:14











    • @MarkRotteveel I know but this felt like the simplest way to move forward.

      – Joakim Danielson
      Jan 3 at 14:27














    1












    1








    1







    Update 2



    Here is an abbreviated version using try-with-resource instead. Code is simpler and shorter



    public String RegisterUser(... ) {
    boolean trovato = false;
    int authorized=0;

    SqliteConnection sqlite = new SqliteConnection();
    String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";
    String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"' and Password='"+password+"'";

    try (java.sql.Connection con = sqlite.connect();
    Statement statement = con.createStatement();
    Statement updStatement = con.createStatement();
    ) {
    ResultSet rsActiveServices = con.createStatement().executeQuery(query);
    // handle result set as before
    } catch(SQLException e) {
    e.printStackTrace();
    System.out.println("errore" + e);
    }
    if(trovato==false) {
    createUser(username, password, name, surname, appname, email, ip)
    }
    return "username: " + username;
    }


    private createUser(String username, String password, String name, String surname, String appname, String email, String ip {
    String query1="INSERT INTO Apps (Username,Password,Name,Surname,Email,AppName,Ip,Authorized,Token) VALUES ('" + username + "'," + "'" +password +"','" + name + "','" + surname + "','" +email + "','" + appname + "','"+ip+"','"+authorized+"','"+token+"')";
    SqliteConnection sqlite = new SqliteConnection();
    String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";

    try (java.sql.Connection con = sqlite.connect();
    Statement statement = con.createStatement();) {
    updStatement.executeUpdate(query1);
    } catch(SQLException e) {
    e.printStackTrace();
    System.out.println("errore" + e);
    }
    }




    It could very well be that your prepared statement isn't properly closed. Change



    ResultSet rsActiveServices = con.createStatement().executeQuery(query);


    to



    statement = con.createStatement();
    ResultSet rsActiveServices = statement.executeQuery(query);


    where statement is declared before try



    java.sql.Connection con = null;
    Statement statement = null;


    and then close it in your finally clause



    finally
    {
    try
    {
    statement.close();
    con.close();
    sqlite.close();
    }


    Update 1



    I just noticed that your are trying to close your objects twice which is wrong, remove the first set of close calls and only close within finally {} at the end.






    share|improve this answer















    Update 2



    Here is an abbreviated version using try-with-resource instead. Code is simpler and shorter



    public String RegisterUser(... ) {
    boolean trovato = false;
    int authorized=0;

    SqliteConnection sqlite = new SqliteConnection();
    String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";
    String query="SELECT Username,Password FROM Apps WHERE Username ='"+username+"' and Password='"+password+"'";

    try (java.sql.Connection con = sqlite.connect();
    Statement statement = con.createStatement();
    Statement updStatement = con.createStatement();
    ) {
    ResultSet rsActiveServices = con.createStatement().executeQuery(query);
    // handle result set as before
    } catch(SQLException e) {
    e.printStackTrace();
    System.out.println("errore" + e);
    }
    if(trovato==false) {
    createUser(username, password, name, surname, appname, email, ip)
    }
    return "username: " + username;
    }


    private createUser(String username, String password, String name, String surname, String appname, String email, String ip {
    String query1="INSERT INTO Apps (Username,Password,Name,Surname,Email,AppName,Ip,Authorized,Token) VALUES ('" + username + "'," + "'" +password +"','" + name + "','" + surname + "','" +email + "','" + appname + "','"+ip+"','"+authorized+"','"+token+"')";
    SqliteConnection sqlite = new SqliteConnection();
    String dbPath="C:/Users/l.pellegrini/eclipse-workspace/ClayAPI_dbembedded/claydb.db";

    try (java.sql.Connection con = sqlite.connect();
    Statement statement = con.createStatement();) {
    updStatement.executeUpdate(query1);
    } catch(SQLException e) {
    e.printStackTrace();
    System.out.println("errore" + e);
    }
    }




    It could very well be that your prepared statement isn't properly closed. Change



    ResultSet rsActiveServices = con.createStatement().executeQuery(query);


    to



    statement = con.createStatement();
    ResultSet rsActiveServices = statement.executeQuery(query);


    where statement is declared before try



    java.sql.Connection con = null;
    Statement statement = null;


    and then close it in your finally clause



    finally
    {
    try
    {
    statement.close();
    con.close();
    sqlite.close();
    }


    Update 1



    I just noticed that your are trying to close your objects twice which is wrong, remove the first set of close calls and only close within finally {} at the end.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 3 at 17:37

























    answered Jan 3 at 12:00









    Joakim DanielsonJoakim Danielson

    10.8k3725




    10.8k3725













    • the row of code statement.close(); do error

      – luca pellegrini
      Jan 3 at 13:21











    • finally { try { statement.close(); con.close(); sqlite.close(); } i can't put statement.close(); into finally

      – luca pellegrini
      Jan 3 at 13:34













    • @lucapellegrini, simple mistake by me. You need to declare the variable outside the try clause. I'll update the answer

      – Joakim Danielson
      Jan 3 at 14:08











    • Using try-with-resources is probably better (and shorter).

      – Mark Rotteveel
      Jan 3 at 14:14











    • @MarkRotteveel I know but this felt like the simplest way to move forward.

      – Joakim Danielson
      Jan 3 at 14:27



















    • the row of code statement.close(); do error

      – luca pellegrini
      Jan 3 at 13:21











    • finally { try { statement.close(); con.close(); sqlite.close(); } i can't put statement.close(); into finally

      – luca pellegrini
      Jan 3 at 13:34













    • @lucapellegrini, simple mistake by me. You need to declare the variable outside the try clause. I'll update the answer

      – Joakim Danielson
      Jan 3 at 14:08











    • Using try-with-resources is probably better (and shorter).

      – Mark Rotteveel
      Jan 3 at 14:14











    • @MarkRotteveel I know but this felt like the simplest way to move forward.

      – Joakim Danielson
      Jan 3 at 14:27

















    the row of code statement.close(); do error

    – luca pellegrini
    Jan 3 at 13:21





    the row of code statement.close(); do error

    – luca pellegrini
    Jan 3 at 13:21













    finally { try { statement.close(); con.close(); sqlite.close(); } i can't put statement.close(); into finally

    – luca pellegrini
    Jan 3 at 13:34







    finally { try { statement.close(); con.close(); sqlite.close(); } i can't put statement.close(); into finally

    – luca pellegrini
    Jan 3 at 13:34















    @lucapellegrini, simple mistake by me. You need to declare the variable outside the try clause. I'll update the answer

    – Joakim Danielson
    Jan 3 at 14:08





    @lucapellegrini, simple mistake by me. You need to declare the variable outside the try clause. I'll update the answer

    – Joakim Danielson
    Jan 3 at 14:08













    Using try-with-resources is probably better (and shorter).

    – Mark Rotteveel
    Jan 3 at 14:14





    Using try-with-resources is probably better (and shorter).

    – Mark Rotteveel
    Jan 3 at 14:14













    @MarkRotteveel I know but this felt like the simplest way to move forward.

    – Joakim Danielson
    Jan 3 at 14:27





    @MarkRotteveel I know but this felt like the simplest way to move forward.

    – Joakim Danielson
    Jan 3 at 14:27













    0














    Resolved



    I do errors with open and close connection in Main.. With SQLite the connection you have to open and close everytime it's carried out a query of all type(Insert, Delete,Update ecc..)






    share|improve this answer




























      0














      Resolved



      I do errors with open and close connection in Main.. With SQLite the connection you have to open and close everytime it's carried out a query of all type(Insert, Delete,Update ecc..)






      share|improve this answer


























        0












        0








        0







        Resolved



        I do errors with open and close connection in Main.. With SQLite the connection you have to open and close everytime it's carried out a query of all type(Insert, Delete,Update ecc..)






        share|improve this answer













        Resolved



        I do errors with open and close connection in Main.. With SQLite the connection you have to open and close everytime it's carried out a query of all type(Insert, Delete,Update ecc..)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 7 at 17:08









        luca pellegriniluca pellegrini

        428




        428






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021317%2fdatabase-is-locked-in-sqlite-java%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            WPF add header to Image with URL pettitions [duplicate]