I have an android app that uses Microsoft Access database. when I try to run the app I get this following error:
W/System.err: net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::0.0 given file does not exist: C:\Users\User\Documents\tets.accdb
but when you go to the file location the file exists. I've tried changing the file path and for the most part, it didn't work though sometimes it will give me another error:
for this file path String url = "jdbc:ucanaccess:/C:/Users/User/Documents/tets.accdb";
it gives me this error:
W/System.err: java.sql.SQLException: No suitable driver found for jdbc:ucanaccess:/C:/Users/User/Documents/tets.accdb
I can't seem to understand the difference between the URLs or what is causing this problem. Does anybody know what is causing this issue?
the full code:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.sql.*;
public class Books extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_books);
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String url = "jdbc:ucanaccess://C:\\Users\\User\\Documents\\tets.accdb";
try {
Connection con = DriverManager.getConnection(url);
Statement statement = con.createStatement();
ResultSet res =statement.executeQuery("SELECT * FROM tets");
while(res.next()){
System.out.println(res.getInt(1));
}
con.close();
statement.close();
res.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}