mysql 不能连接错了!
<%@ page language="java" contentType="text/html; charset=gb2312"pageEncoding="gb2312"%>
<%@page import="java.sql.*" %>
<!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=gb2312">
<title>Insert title here</title>
</head>
<body>
<%Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("org.gjt.mm.mysql.Driver");
}
catch(ClassNotFoundException e1){
out.print("类找不到!");
}
try{
con=DriverManager.getConnection("jdbc:mysql:localhost:8080zwz","text","123");
sql=con.createStatement();
rs=sql.executeQuery("select *from star");
out.print("<table border>");
out.print("<tr><td colspan=4 align=certer>歌手有这么些</td></tr>");
out.print("<tr>");
out.print("<td width=40>"+"标号");
out.print("<td width=400>"+"姓名");
out.print("<td width=40>"+"地区");
out.print("<td width=100"+"性别");
out.print("</tr>");
while (rs.next())
{
out.print("<tr>");
out.print("<td>"+rs.getLong(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.print("<td>"+rs.getString(4)+"</td>");
out.print("<td><a href='index.jsp?stat_id="+rs.getLong(1)+"'>我要买!</a></td>");
out.print("</tr>");
out.print("</table>");
con.close();
}
}
catch(SQLException e2)
{
out.print("sql有错!");
}
%>
</body>
</html>
运行后得到了只有“sql有错!”请各位高手指出错误!谢谢 !~!
搜索更多相关主题的帖子:
content PUBLIC import mysql title
----------------解决方案--------------------------------------------------------
select *from star-->select * from star
----------------解决方案--------------------------------------------------------
不亏是版主,这样都能看出错误来
另外建议楼主不要用这样的代码
程序代码:
catch(SQLException e2)
{
out.print("sql有错!");
}
{
out.print("sql有错!");
}
起码输出 错误信息,这样能更快地地位出错的地方
----------------解决方案--------------------------------------------------------
路过的时候发现了一个很奇怪的端口号:8080zwz
con=DriverManager.getConnection("jdbc:mysql:localhost:8080zwz","text","123");
----------------解决方案--------------------------------------------------------
你这个是在JSP页面写的,不是还有一个Connection.java嘛,那个呢?
还有Dao 也没注明,你继承的子类呢?
----------------解决方案--------------------------------------------------------
还真没见过这样的URL驱动:jdbc:mysql:localhost:8080zwz
一直都用这个:jdbc:mysql://localhost:3306/databasesname
----------------解决方案--------------------------------------------------------
sql语句改过来就好了吗? 这个url这样的写法没有问题?
----------------解决方案--------------------------------------------------------
sql语句改过来还没好!
----------------解决方案--------------------------------------------------------
con=DriverManager.getConnection("jdbc:mysql:localhost:8080zwz","text","123");
改为
con=DriverManager.getConnection("jdbc:mysql://localhost:8080","text","123");
看看怎么样,要保证你的端口,用户名,密码是正确的,而且端口没有被人占用
----------------解决方案--------------------------------------------------------
mysql中端口名可以不写的 会使用默认的!
lz虽然用的是jsp 但是根本没体现jsp的特性 java代码太多了
so 如果分,请分层
----------------解决方案--------------------------------------------------------