Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Java sqlite connection error

Java sqlite connection error

Scheduled Pinned Locked Moved Java
helpjavadatabasesqlitetutorial
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rafiullah_Omar
    wrote on last edited by
    #1

    Hi everyone i created exe file of a java desktop application which use a sqlite database when i install the project an i run it i give the error of attempt to write a redinly database and sometimes access in denied error how to fix it?

    L R 2 Replies Last reply
    0
    • R rafiullah_Omar

      Hi everyone i created exe file of a java desktop application which use a sqlite database when i install the project an i run it i give the error of attempt to write a redinly database and sometimes access in denied error how to fix it?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Member 11110116 wrote:

      how to fix it?

      With that level of detail it is anyone's guess. Please show the failing code and provide exact details of any error messages.

      R 1 Reply Last reply
      0
      • R rafiullah_Omar

        Hi everyone i created exe file of a java desktop application which use a sqlite database when i install the project an i run it i give the error of attempt to write a redinly database and sometimes access in denied error how to fix it?

        R Offline
        R Offline
        rah_sin
        wrote on last edited by
        #3

        It can be folder read & write permission issue where you are trying to install application

        rahul

        R 1 Reply Last reply
        0
        • R rah_sin

          It can be folder read & write permission issue where you are trying to install application

          rahul

          R Offline
          R Offline
          rafiullah_Omar
          wrote on last edited by
          #4

          Then how to fix it

          J 1 Reply Last reply
          0
          • L Lost User

            Member 11110116 wrote:

            how to fix it?

            With that level of detail it is anyone's guess. Please show the failing code and provide exact details of any error messages.

            R Offline
            R Offline
            rafiullah_Omar
            wrote on last edited by
            #5

            i just want to insert some data there is no more and difficult code connectivity code:

            import java.sql.Connection;
            import java.sql.DriverManager;
            import java.sql.Statement;
            import javax.swing.JOptionPane;
            public class Sqliteconn {
            public static Statement sqliteStmt()
            {
            try{
            Class.forName("org.sqlite.JDBC");
            Connection conn = DriverManager.getConnection("jdbc:sqlite:B12MSqlite.sqlite");
            Statement stmt=conn.createStatement();
            return stmt;
            }
            catch(Exception e)
            {
            JOptionPane.showMessageDialog(null, e);
            return null;
            }
            }

            }

            and insert Button Code:

            String query="Insert into Employee values('"+txtID.getText()+"','"+txtName.getText()+"','"+txtFName.getText()+"','"+txtEmail.getText()+"')";
            try{
            Sqliteconn.sqliteStmt().execute(query);
            }
            catch(Exception e)
            {
            JOptionPane.showMessageDialog(null, e);
            }

            Erorr messages java.sql.sqlexception attempt to write a readonly database

            L 1 Reply Last reply
            0
            • R rafiullah_Omar

              i just want to insert some data there is no more and difficult code connectivity code:

              import java.sql.Connection;
              import java.sql.DriverManager;
              import java.sql.Statement;
              import javax.swing.JOptionPane;
              public class Sqliteconn {
              public static Statement sqliteStmt()
              {
              try{
              Class.forName("org.sqlite.JDBC");
              Connection conn = DriverManager.getConnection("jdbc:sqlite:B12MSqlite.sqlite");
              Statement stmt=conn.createStatement();
              return stmt;
              }
              catch(Exception e)
              {
              JOptionPane.showMessageDialog(null, e);
              return null;
              }
              }

              }

              and insert Button Code:

              String query="Insert into Employee values('"+txtID.getText()+"','"+txtName.getText()+"','"+txtFName.getText()+"','"+txtEmail.getText()+"')";
              try{
              Sqliteconn.sqliteStmt().execute(query);
              }
              catch(Exception e)
              {
              JOptionPane.showMessageDialog(null, e);
              }

              Erorr messages java.sql.sqlexception attempt to write a readonly database

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              A couple of things first in the following code:

              String query="Insert into Employee values('"+txtID.getText()+"','"+txtName.getText()+"','"+txtFName.getText()+"','"+txtEmail.getText()+"')";
              try{
              Sqliteconn.sqliteStmt().execute(query);
              }

              Do not use string concatenation in this way to create SQL statements, it leaves your code vulnerable to SQL injection, and the corruption or destruction of your database. Use properly constructed parameterised statements. Also you should split the execute statement into two parts for easier debugging. As to your error, you need to establish why the database is not writable by your program. Do you have permission to write in the folder where the database is stored?

              R 1 Reply Last reply
              0
              • L Lost User

                A couple of things first in the following code:

                String query="Insert into Employee values('"+txtID.getText()+"','"+txtName.getText()+"','"+txtFName.getText()+"','"+txtEmail.getText()+"')";
                try{
                Sqliteconn.sqliteStmt().execute(query);
                }

                Do not use string concatenation in this way to create SQL statements, it leaves your code vulnerable to SQL injection, and the corruption or destruction of your database. Use properly constructed parameterised statements. Also you should split the execute statement into two parts for easier debugging. As to your error, you need to establish why the database is not writable by your program. Do you have permission to write in the folder where the database is stored?

                R Offline
                R Offline
                rafiullah_Omar
                wrote on last edited by
                #7

                thanks for your reply my database is stored in same folder with project and how to allow the permission of writing?

                L 1 Reply Last reply
                0
                • R rafiullah_Omar

                  thanks for your reply my database is stored in same folder with project and how to allow the permission of writing?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Check permissions and access rights of the folder and the database and see why your application cannot write to the file.

                  1 Reply Last reply
                  0
                  • R rafiullah_Omar

                    Then how to fix it

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #9

                    Obviously when it is a "folder read & write permission issue" then you fix it by fixing that issue. And that is not a java issue.

                    R 1 Reply Last reply
                    0
                    • J jschell

                      Obviously when it is a "folder read & write permission issue" then you fix it by fixing that issue. And that is not a java issue.

                      R Offline
                      R Offline
                      rafiullah_Omar
                      wrote on last edited by
                      #10

                      bro it works properly when i open and run it in netbeans but when i create its setup and install and run it , it give the error.

                      L 1 Reply Last reply
                      0
                      • R rafiullah_Omar

                        bro it works properly when i open and run it in netbeans but when i create its setup and install and run it , it give the error.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        It is no good reposting this information repeatedly, until you have found out why you are prevented from writing to this database. Look at the directories where the files are installed and check the permissions on them, and do the same for all associated files.

                        R 1 Reply Last reply
                        0
                        • L Lost User

                          It is no good reposting this information repeatedly, until you have found out why you are prevented from writing to this database. Look at the directories where the files are installed and check the permissions on them, and do the same for all associated files.

                          R Offline
                          R Offline
                          rafiullah_Omar
                          wrote on last edited by
                          #12

                          Thank you bro u solved the problem tnx again

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups