- Forum posts: 1
Dec 19, 2014, 3:50:09 PM via Website
Dec 19, 2014 3:50:09 PM via Website
Hi guys,
Iam new in developing android applications.
I want to use Jackcess in Android-App for access an existing accdb database.
I'm using eclipse juno.
My jar files:
commons-lang-2.6.jar
commons-logging-1.1.1.jar
hsqldb.jar
jackcess-2.0.7.jar
jackcess-encrypt-2.0.2.jar
jtds-1.3.1.jar
log4j-1.2.7.jar
My code:
package com.example.siferfinal;
import java.io.File;
import java.io.IOException;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.Table;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ConectarBD();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void ConectarBD(){
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
System.setProperty("com.healthmarketscience.jackcess.brokenNio","true");
System.setProperty("com.healthmarketscience.jackcess.resourcePath ","res/raw/");
try
{
Database db = DatabaseBuilder.open(new File("sif.mdb"));
Table tblTempoAnt = db.getTable("tblTempoAnt");
System.out.println(tblTempoAnt.toString());
}
catch (IOException e)
{
e.printStackTrace();
}
}
Public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I added my database to res/raw folder.
On the next line
Database db = DatabaseBuilder.open(new File("sif.mdb"));
I get an error - "java.io.FileNotFoundException: given file does not exist: sif.mdb"
What am i doing wrong ?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.