I have a system that is running on web and a MySQL database; these include the database connection factory to MySQL, Bean/Model, DAO and Servlets. And I am planning to create an Android application in mobile device that also needs to access the information in the MySQL. Apparently, the connection to MySQL does not work similarly with the web-based system. There are errors in the connection to MySQL in Android app. Code below
public Connection getConnection() {
try {
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup(getDatasource());
Connection conn = ds.getConnection();
return conn;
} catch (NamingException ex) {
Logger.getLogger(DBConnectionFactoryImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(DBConnectionFactoryImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
How can I exactly connect my mobile application with my existing MySQL database?