Andy Andy - 1 year ago 157
MySQL Question

my database is not getting connected simple on jsp page build on netbeans

The following is a simple code to show wheather database is connected or

not.I am using mysql workbench and netbeans.It is showing not connected

and the glassfish server is showing some warnings which are shown after
the code.


<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
Connection conn = null;

conn =DriverManager.getConnection
=convertToNull","root", "root");
out.print("connected to database successfully");

}catch(Exception e)
out.print("not connected to database");


<warning and info*/
Info: Loading application __admingui done in 7,651 ms
Warning: Context path from ServletContext: differs from path from
Info: Redirecting to /index.jsf
Info: Admin Console: Initializing Session Attributes...
Warning: Could not open/create prefs root node Software\JavaSoft\Prefs at
root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Warning: Cannot create update center Image for C:\Program
Files\glassfish->4.1.1; Update Center functionality will not be available
in Admin Console

Answer Source

Try this maybe it is a syntax error also check if you have correct jar file or not-

Connection conn = null;

 conn =DriverManager.getConnection
 ("jdbc:mysql://localhost:3306/userpass","root", "root"); //removed after userpass
     out.println("connected to database successfully");
     out.println("not connected to database");

  }catch(Exception e)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download