Results 1 to 4 of 4

Thread: NetBeans - Java ME

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    136

    NetBeans - Java ME

    Hi there,
    my question is how to integrate with MySQL database.
    i had tried this code, but it return "package java.sql does not exist".

    Code:
     
    import java.io.*;
    import java.util.*;
    import javax.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class DBConnection extends HttpServlet {
      public void service(HttpServletRequest request,HttpServletResponse response)
        throws IOException, ServletException{
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>Servlet JDBC</title></head>");
        out.println("<body>");
        out.println("<h1>Servlet JDBC</h1>");
        out.println("</body></html>");
        // connecting to database
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
          Class.forName("com.mysql.jdbc.Driver");
          con =DriverManager.getConnection ("jdbc:mysql://192.168.10.59:3306/example",
    
          "root", "root");
          stmt = con.createStatement();
          rs = stmt.executeQuery("SELECT * FROM servlet");
          // displaying records
          while(rs.next()){
            out.print(rs.getObject(1).toString());
            out.print("\t\t\t");
            out.print(rs.getObject(2).toString());
            out.print("<br>");
          }
        } catch (SQLException e) {
          throw new ServletException("Servlet Could not display records.", e);
          } catch (ClassNotFoundException e) {
            throw new ServletException("JDBC Driver not found.", e);
          } finally {
            try {
              if(rs != null) {
                rs.close();
                rs = null;
              }
              if(stmt != null) {
                stmt.close();
                stmt = null;
              }
              if(con != null) {
                con.close();
                con = null;
              }
            } catch (SQLException e) {}
          }
          out.close();
        }
      }
    it's seem like only RecordStore or FileConnector can storing information in a mobile device but how to integrate with MySQL database?
    i want to let the user key in UserName and Password then access to my application.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: NetBeans - Java ME

    And the login is done on the user end why??
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    136

    Re: NetBeans - Java ME

    And the login is done on the user end why??
    Yes~

    i'm had download some sample code and i realised J2ME doesn't support compact database.
    Normally, J2ME just pass parameter to the website and let the website itself connect to database.

    Please let me know if i was wrong. thanks

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: NetBeans - Java ME

    No, that's right. You cannot expect a mobile to run a DB server. The mobile client doesn't have the processing power for a server. Besides, 1 server per client defeats the purpose of naming it a server
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width