1

I'm new with getting a java applet to connect to a mysql database. This is my first time attempting to do so.

I've researched a lot and have seen lots of tutorials, but I'm still facing problems. Since my java applet goes to a browser, I did sign it. I've also been using jdbc and the jar file has been imported properly to my library.

I've also been using 000webhost.com and have been trying to connect to the database from both the IDE and the browser. I also got two of my friends to help me. One of them had to go early and the other don't know where I went wrong.

Here is my codes: http://prntscr.com/oagfi

enter image description here

I've come to the conclusion that the DriverManager.getConnection(...) is whats giving me problems.

The error reads... http://prntscr.com/oaetz

enter image description here

I have also tried looking up the cause but still no luck.

Is there anything I can do to fix this problem? I'm curious of what this cause mean and why I'm having trouble.

BenMorel
  • 34,448
  • 50
  • 182
  • 322

5 Answers5

1

If you are on free 000webhost accounts than you cant access your database outside your host account.

Maki325
  • 32
  • 1
  • 4
0

Check the version of JDBC Connector you are using. Also following link will help you to do JDBC Connection -

Connect Java to a MySQL database

Community
  • 1
  • 1
Avinash T.
  • 2,280
  • 2
  • 16
  • 23
  • I just learned something new. Could my problem be because of this? http://prntscr.com/oamzu Also, I skimmed through what you sent me. Thanks for the link but I need to sleep. I'll read it tomorrow. – Aladdin Seaifan Jan 06 '13 at 09:17
0

Are you behind a firewall/proxy server? If so, does it permit outgoing connections on port 3306 you're using? This was a problem I had once, our corporate firewall was so crippled we could only talk out via the http /https ports.

Steve Atkinson
  • 1,219
  • 2
  • 12
  • 30
  • I've tried disabling my firewall temporarily. I also tried sending the url to the java applet to some of my friends, they got the same problem. – Aladdin Seaifan Jan 06 '13 at 08:12
0

From Applet (if my memory not fail), you must use Signed code and/or you can only connect to remotehost from Applet was downloaded... if not, security exceptions are throwed. (applets run on a limited/restricted sandbox)

ggrandes
  • 2,067
  • 22
  • 16
  • remote mysql listen in 0.0.0.0/ANY in 3306, accepting remote connections, permissions are right? you can "**telnet host 3306**" and respond like this... **`5.0.xx-Max-log....`**?? – ggrandes Jan 06 '13 at 09:33
  • btw: the good and secure method is avoid open mysql to "world", and use REST service or similar... :-) – ggrandes Jan 06 '13 at 09:36
  • I will look into that tomorrow. I'm extremely tired right now. Thanks for your help. I'll ask questions tomorrow if you don't mind. – Aladdin Seaifan Jan 06 '13 at 09:47
  • Omg, I am so sorry. I just realized that I posted the wrong url. I feel so embarrassed. Anyways, I deleted my post and I'll send you the correct url. Could this be the problem I'm having?: http://prntscr.com/oamzu – Aladdin Seaifan Jan 06 '13 at 19:20
0
        /* RegistrationDAO*/


        /*
         * To change this template, choose Tools | Templates
         * and open the template in the editor.
         */
        package com.tcs.ignite.connectionname.DAO;

        import com.tcs.ignite.connectionname.bean.Register;
        import com.tcs.ignite.connectionname.util.Eyeconnection;
        import java.sql.Connection;
        import java.sql.PreparedStatement;
        import java.sql.ResultSet;

        public class RegisterDAO {
            private Connection connection;
             private connectionnamecon;

            public RegisterDAO() {
                con = new connectionname();
            }

            public boolean insertRecords(Register rg) throws Exception {

                connection = con.openConnection();

                String select="select * from register";
                PreparedStatement ps=connection.prepareStatement(select);
                ResultSet rs=ps.executeQuery();
                while(rs.next())
                {
                    String email=rs.getString("user_email");
                    if(rg.getUser_email().equals(email))
                    {
                        return false;
                     }
                }
               ps.close();



                String query = "insert into register(user_Fname,user_Lname,password,confirm_pass,contact_no,user_email,user_address,user_pincode) VALUES (?,?,?,?,?,?,?,?)";
                ps = connection.prepareStatement(query);

                ps.setString(1, rg.getUser_Fname());
                ps.setString(2, rg.getUser_Lname());
                ps.setString(3, rg.getPassword());
                ps.setString(4, rg.getConfirm_pass());
                ps.setString(5, rg.getContact_no());
                ps.setString(6, rg.getUser_email());
                ps.setString(7, rg.getUser_address());
                ps.setString(8,rg.getUser_pincode());

                int rowcount = ps.executeUpdate();
                con.closeConnection();
                if (rowcount == 0) {
                    return false;
                } else {
                    return true;
                }
            }
        }

    /*
    RegistrationManager*/
     */
    package com.tcs.ignite.connectionname.Manager;

    import com.tcs.ignite.connectionname.DAO.RegisterDAO;
    import com.tcs.ignite.connectionname.bean.Register;


    public class RegisterManager {
         public boolean insertManager(Register rg) throws Exception {

            RegisterDAO regdao = new RegisterDAO();
            boolean result = regdao.insertRecords(rg);
            if(result==true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
 /*RegistrationServlet*/

     protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {

            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {

              Register reg=new Register();

              reg.setUser_Fname(request.getParameter("firstname"));
              reg.setUser_Lname(request.getParameter("lastname"));
              reg.setPassword(request.getParameter("password"));
              reg.setConfirm_pass(request.getParameter("confirm_password"));
              reg.setContact_no(request.getParameter("mobile"));
              reg.setUser_email(request.getParameter("email"));
              reg.setUser_address(request.getParameter("address"));
              reg.setUser_pincode(request.getParameter("pincode"));




              RegisterManager regManager=new RegisterManager();
              if(regManager.insertManager(reg)){
    //               RequestDispatcher requestDispatcher= request.getRequestDispatcher("TCSBLUE.jsp");
    //               requestDispatcher.forward(request, response);
                  HttpSession session = request.getSession(true);
                   session.setAttribute("loginid", reg.getUser_email());
                   //out.print(session.getAttribute("loginid"));
                  out.write("Successfully Registered...");
              }
              else
              {
    //              RequestDispatcher requestDispatcher= request.getRequestDispatcher("Error.jsp");
    //               requestDispatcher.forward(request, response);
                  out.write("Something is going wrong....");
              }
            }
            catch(Exception ex)
            {
                Logger.getLogger(Connection.class.getName()).log(Level.SEVERE, null, ex);
            }
            finally {            
                out.close();
            }

        }