tomcat连接mysql数据库数据库的问题

yeyuanzhi2000 2008-12-29 07:42:54
我把mysql-connector-java-3.1.14-bin-g.jar和mysql-connector-java-3.1.14-bin.jar放进%tomcat5.5%\common\lib下面后,运行下面的程序:
<%@ page contentType="text/html;charset=gb2312"%>   
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/new2007"
//soft为你的数据库名
String user="root";
String password="123";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from news";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

结果报错.为什么?
我安装的是JDK1.6和tomcat5.5,mysql5.0后,要不要进行环境变量的配置?怎么配置?谢谢!!
...全文
85 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fys249931556 2008-12-29
  • 打赏
  • 举报
回复
发现这个CSDN,有时候刷新真郁闷。。
自己回复了以后发现前边有人回了,而且是几分钟前的。
fys249931556 2008-12-29
  • 打赏
  • 举报
回复
都提示你少分号了。
String url ="jdbc:mysql://localhost/new2007?user=root&password=123&useUnicode=true&characterEncoding=8859_1"
后边加个分号。。
楼主细心点,最好用个IDE工具。。推荐MyEcplise
yeyuanzhi2000 2008-12-29
  • 打赏
  • 举报
回复
谢谢!!
MuBeiBei 2008-12-29
  • 打赏
  • 举报
回复
String url ="jdbc:mysql://localhost/new2007?user=root&password=123&useUnicode=true&characterEncoding=8859_1"

少分号 ;
yeyuanzhi2000 2008-12-29
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yeyuanzhi2000 的回复:]
对不起,我太粗心了。是这样的:

HTML code<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/new2007?user=root&password=123&useUnicode=true&characterEncoding=8859_1"
//testDB为你的数据库名
Connection conn= DriverManager.getConnection(ur…
[/Quote]
还是提示错误啊?
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 6 in the jsp file: /index.jsp
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
3: <html>
4: <body>
5: <%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
6: String url ="jdbc:mysql://localhost/new2007?user=root&password=123&useUnicode=true&characterEncoding=8859_1"
7: //testDB为你的数据库名
8: Connection conn= DriverManager.getConnection(url);
9: Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);



yeyuanzhi2000 2008-12-29
  • 打赏
  • 举报
回复
对不起,我太粗心了。是这样的:
<%@ page contentType="text/html;charset=gb2312"%>   
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/new2007?user=root&password=123&useUnicode=true&characterEncoding=8859_1"
//testDB为你的数据库名
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from news";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
glglglglglgllll 2008-12-29
  • 打赏
  • 举报
回复
LS说的对
blueram 2008-12-29
  • 打赏
  • 举报
回复
<%Class.forName("org.postgresql.Driver").newInstance();
错了吧;
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/drp?user=root&password=root");
MuBeiBei 2008-12-29
  • 打赏
  • 举报
回复
Class.forName("com.mysql.jdbc.Driver");
"jdbc:mysql://localhost:3306/lilin";

我连mysql是这么写
凌霄野鹤 2008-12-29
  • 打赏
  • 举报
回复
你这个页面是html是不能调用的!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧