以下是显示wheather数据库已连接或
不,我正在使用mysql工作台,netbeans.It显示没有连接
而glassfish服务器正在显示一些警告,这些警告显示在代码之后。
code
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn =DriverManager.getConnection
("jdbc:mysql://localhost:3306/userpass?zeroDateTimeBehavior
=convertToNull","root", "root");
if(conn!=null)
{
out.print("connected to database successfully");
}
}catch(Exception e)
{
out.print("not connected to database");
}
%>
</body>
</html>
<warning and info*/
Info: Loading application __admingui done in 7,651 ms
Warning: Context path from ServletContext: differs from path from
bundle:/
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发布于 2016-07-06 13:12:44
尝试一下,也许这是语法错误,也可以检查是否有正确的jar文件-
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn =DriverManager.getConnection
("jdbc:mysql://localhost:3306/userpass","root", "root"); //removed after userpass
if(conn!=null)
out.println("connected to database successfully");
else
out.println("not connected to database");
}catch(Exception e)
{
out.println(e);
}发布于 2016-05-26 11:27:11
首先,我要说用jsp编写数据库代码不是code.All的好方法,数据库代码和业务逻辑必须用servlet编写,或者普通的java class.Jsp是视图,经过servlet处理后,我们可以使用jsp显示输出。
This is just a warning, you can ignore it if you want.引发此警告是因为您的上下文中可能有一个前导斜杠(即/) - glassfish-web.xml中的根(应该位于WAR的web.xml文件夹中)。
如果删除前面的斜杠,您可能会删除警告,因此glassfish-web.xml看起来类似于以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<context-root>SalutationApp-war</context-root>
</glassfish-web-app>
I hope I helped u.https://stackoverflow.com/questions/37458958
复制相似问题