注册 登录
编程论坛 J2EE论坛

mysql 不能连接错了!

zhangzwz 发布于 2010-08-13 14:22, 756 次点击
<%@ 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.
<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有错!”请各位高手指出错误!谢谢 !~!
9 回复
#2
cnfarer2010-08-13 16:41
select *from star-->select * from star
#3
shellingford2010-08-13 17:13
不亏是版主,这样都能看出错误来

另外建议楼主不要用这样的代码
程序代码:
catch(SQLException e2)
{
out.print("sql有错!");
  }

起码输出 错误信息,这样能更快地地位出错的地方
#4
流星雨2010-08-16 15:08
路过的时候发现了一个很奇怪的端口号:8080zwz
con=DriverManager.getConnection("jdbc:mysql:localhost:8080zwz","text","123");
#5
ablikim2010-08-16 15:24
你这个是在JSP页面写的,不是还有一个Connection.java嘛,那个呢?
     还有Dao 也没注明,你继承的子类呢?
#6
失眠的泪水2010-08-16 23:05
还真没见过这样的URL驱动:jdbc:mysql:localhost:8080zwz
一直都用这个:jdbc:mysql://localhost:3306/databasesname
#7
syg54342010-08-17 14:42
sql语句改过来就好了吗? 这个url这样的写法没有问题?
#8
zhangzwz2010-08-17 19:04
sql语句改过来还没好!
#9
syg54342010-08-17 19:20
con=DriverManager.getConnection("jdbc:mysql:localhost:8080zwz","text","123");
改为
con=DriverManager.getConnection("jdbc:mysql://localhost:8080","text","123");
看看怎么样,要保证你的端口,用户名,密码是正确的,而且端口没有被人占用
#10
maxliz2010-08-22 13:03
mysql中端口名可以不写的 会使用默认的!
lz虽然用的是jsp 但是根本没体现jsp的特性 java代码太多了
so 如果分,请分层
1