Java sqlite connection error
-
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?
-
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?
-
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?
-
It can be folder read & write permission issue where you are trying to install application
rahul
Then how to fix it
-
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.
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
-
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
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?
-
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?
thanks for your reply my database is stored in same folder with project and how to allow the permission of writing?
-
thanks for your reply my database is stored in same folder with project and how to allow the permission of writing?
-
Then how to fix it
-
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.
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.
-
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.
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.
-
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.
Thank you bro u solved the problem tnx again