0

I have been using sql server with jdbc to connect to server.Now I want my app to be connected to local server i.e. sqlite.I found out that there is sqlite jdbc driver also...I need to know how can I implement the same...I tried to implement but am getting an error like " open failed: EACCES (Permission denied)".Can any one help me on this..This is what I have done so far...

try {
            if(sqlite){
                Class.forName("org.sqlite.JDBC");


                ConnURL = "jdbc:sqlite:DbEasyJune21.db";

            }
            else {
                Class.forName(classs);
                ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
                        + "databaseName=" + db + ";sendStringParametersAsUnicode=false;user=" + un + ";password="
                        + password + ";";
            }
            conn = DriverManager.getConnection(ConnURL);
            System.out.println("Connection"+conn);
        } catch (SQLException se) {
            Log.e("ERRO", se.getMessage());
        } catch (ClassNotFoundException e) {
            Log.e("ERRO", e.getMessage());
        } catch (Exception e) {
            Log.e("ERRO", e.getMessage());
        }

Thanks in Advance

eureka
  • 55
  • 6
  • A PHP script on the server will be easier I guess. – Sourav Kanta Jun 27 '16 at 09:00
  • No my db is sqlite... Its not in server.. – eureka Jun 27 '16 at 09:05
  • Why don't you use SQLiteOpenHelper? – Ajit Pratap Singh Jun 27 '16 at 09:32
  • Actually I need to use prepared statements ..If I am using sqliteOpenHelper I have to change the whole existing code – eureka Jun 27 '16 at 09:36
  • If nothing changed, you can't use the sqlite driver. The Sqlite in android is specific to it. But you can use PreparedStatement – AxelH Jun 27 '16 at 09:43
  • To use prepared statement with the Android SDK http://stackoverflow.com/questions/433392/how-do-i-use-prepared-statements-in-sqlite-in-android – AxelH Jun 27 '16 at 09:44
  • Thank You @AxelH for that..But what if I need to switch between server db and sqlite db.? If am using Sqlite jdbc driver I just need to change the connection string... – eureka Jun 27 '16 at 09:50
  • Here is also an answer to your question http://stackoverflow.com/questions/1728476/does-android-support-jdbc in short, you are running an android sdk and not Java SE, so bugs a likely to happen. I would try to create a proxy to write only once the query and and the parameters (in a list of some kind). Then create an interpretor for both system (jdbc and Android SQLite) to create the Statements and to put the parameters. This should be esay for simple request. – AxelH Jun 27 '16 at 12:19
  • I dint get you.. Could you plz help me with an example – eureka Jun 28 '16 at 03:58

0 Answers0