I'm trying to create a Web Service in JAVA to be consumed by an Android application. I need to use a Cloud technology, and only found OpenShift free and best recommended for now ... Well, I've already created my project in Eclipse. I already have all the tools. I already sent the project to OpenShift, etc. The problem is as follows: (Note: I'm a beginner)
I created a connection class with the database:
package conectaMySql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConectaMySql {
private static final String URL = "link do MySql dado pela OpenShift";
private static final String USER = "login do MySql dado pela OpenShift";
private static final String SENHA = "senha do MySql dada pela OpenShift";
public static Connection obterConexao() throws SQLException{
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
return DriverManager.getConnection(URL, USER, SENHA);
}
}
I created another class with the following data:
package classesDao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import classes.*;
import conectaMySql.*;
public class AdministradorDao {
public boolean insertAdmin(Administrador admin){
try {
Connection conn = ConectaMySql.obterConexao();
String queryInserir = "INSERT INTO Administrador VALUES (?, ?)";
PreparedStatement ppStm = conn.prepareStatement(queryInserir);
ppStm.setString(1, admin.getLogin());
ppStm.setString(2, admin.getSenha());
ppStm.executeUpdate();
conn.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
Disregarding the MVC concept, lol ... How can I make this class available as a service? I researched a lot on the internet, but I do not handle English very well (I know I'm chipped, and the translation tool helped me damn good), but unfortunately I did not find anything concrete. I saw some things about web.xml, etc ... But I'm still in the dark! And now, who can help me?