myeclipse连接mysql数据库出现问题
我使用myeclipse做作业写的代码连接数据库是出现这样的错误,求解释!
代码如下:
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!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=gbk">
<title>Test Mysql</title>
</head>
<body>
<%@ page import="java.sql.*" %>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Testdb","root","");
Statement st=conn.createStatement();
st.setMaxRows(20);
String sqlStr="select * from rgusers";
ResultSet rs=st.executeQuery(sqlStr);
while(rs.next())
{%>
<%=rs.getString("username")%> <br>
<%
}
rs.close(); st.close(); conn.close();
%>
</body>
</html>
代码没错误,数据库的驱动mysql-connector-java-5.1.21-bin.jar,也加载上去了
用的是mysqlworkbench写的数据,在mysql命令中可以查询到,就用jsp查看时出现错误
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
就这个,我同学也出现了这个问题
[最优解释]
jdbc是不是配置错误了额,
String url="jdbc:mysql://localhost:3306/sample_db?user=root&password=your_password";,你按照这个配置试一下