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);

}
Minimax
  • 121
  • 1
  • 5
  • 20
  • 1
    It does not really matter if an IDE like NetBeans "has" Derby (whatever "has" means in this case). Android does not have Derby. It certainly should not be running a Derby daemon on `localhost:1527` on the device itself. – CommonsWare Jan 13 '15 at 21:06
  • 1
    if you wanna have a db on the device itself google for SQLite – tung Jan 13 '15 at 21:10

1 Answers1

1

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.

SummerCode
  • 1,403
  • 1
  • 14
  • 28
  • 2
    To expand on this: when you run your android application on your device (emulator/phone/tablet) than `localhost` is that device. It is not your developer machine running IDE and Derby. – Radim Jan 14 '15 at 10:46
  • 1
    Thank you. Although I was aware how unsafe it is to have a database that I access directly from my smartphone, it still is possible. We're not going to release this app, just make one and learn mistakes like this during the course. Having SQLite would make the app theoretically too big, wouldn't it? But I'll check it out – Minimax Jan 17 '15 at 19:14