Search code examples
javaandroidnetbeansderbyjavadb

Making a database for an Android app in Netbeans 8.0.2


Let me start off by saying we're completely newbies in android programming, but are learning the basics using various tutorials on youtube and other sites. I use Netbeans IDE and have installed the Android SDK. The app we want to create is basically an app where you can take a look at various recipes.

Sine Netbeans has this Apache Derby database, I've added a few recipe names in the database. Now using a code from this websitehttp://www.homeandlearn.co.uk/java/java_and_databases.html, I've tried to connect to the database directly from the onCreate class.

The problem is that when I run an emulator it doesn't output the SQL statement.

public void onCreate(Bundle savedInstanceState)
{


    try {
    String host,uName,uPass;
    host="jdbc:derby://localhost:1527/Recipes [dico on DICO]";
    uName="admin";
    uPass="admin";
    Connection con = DriverManager.getConnection(host, uName, uPass);
    Statement stmt = con.createStatement();

    String SQL = "select NAME from BREAKFAST";
    ResultSet rs = stmt.executeQuery(SQL);
    rs.next( );
    String fName=rs.getString("NAME");
    System.out.println(fName);


    }
    catch(SQLException err){
        System.out.println(err.getMessage());
    }


    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

}

Solution

  • You do not want to have a database that you access directly from your cell phone on the pc, but what you should be doing is either a database for storing information on the phone(like SQLite or ORMLite ) or remotely access the database through a WebService that connects to a server which sends back the desired information related to the database content.