Bueno aca les dejo una aplicación con J2ME, lo que hago es conectar una aplicación móvil mediante un servlets que este se coneta a MySQL, y una pequeña pagina JSP... por cierto todo esta en NetBeans, es algo muy sencillo, luego estaré subiendo todo un sistema Midlet completo.
Acá el código
copyright
BD:
GRANT ALL PRIVILEGES ON servidorlaptop.* TO 'TuUser'@'localhost' IDENTIFIED BY 'TuPass' WITH GRANT OPTION;
JSP:
<%-- Document : index Created on : 29/11/2010, 10:04:46 PM
Author : Henry Paz --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="HelloServlets" method="POST">
Ingrese su nombre: <input type="text" name="nombre" value="" size="45" />
Ingrese su password: <input type="text" name="pass" value="" size="45" />
<input type="submit" value="Enviar" name="enviar" />
</form>
</body>
</html>
SERVLETS:
//supongo que ya saben como cargar los Servlet, pero el nombre de la clase es: HelloServlets extends HttpServlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String usuario = request.getParameter("nombre");
String clave = request.getParameter("pass");
String respuesta = "";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conexion = DriverManager.getConnection("jdbc:mysql://" +
"localhost:3306/ServidorLaptop", "root", "root");
Statement sentencia = conexion.createStatement();
ResultSet rs = sentencia.executeQuery("SELECT idUser FROM " +
"user WHERE User='" + usuario + "' AND password='" + clave + "'");
rs.last();
if (rs.getRow() == 0) {
respuesta = "0";
} else {
respuesta = String.valueOf(rs.getInt(1));
}
conexion.close();
sentencia.close();
} catch (Throwable t) {
out.println("Error. " + t.toString()); //mensaje = "Error. " + t.toString();
} finally {
out.println(respuesta);
out.close();
}
MIDLET:
Bueno se puede correr con ToolKit para celulares, y por cierto para hacer correr desde el celular y conectarse con la laptop se tiene que configurar la red.
http://www.4shared.com/file/_tfbtGy-/Coneccion.html
http://www.4shared.com/file/lMXDyVVV/Coneccion.html
copyright