初学者,请大家帮忙看我的一小段代码有何问题?

augustfox 2004-03-30 10:04:02
我的代码是:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=GB2312"
pageEncoding="GB2312"
%>
<%@ page import="java.sql.*"%>
<META http-equiv="Content-Type" content="text/html; charset=GB2312">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>db2test.jsp</TITLE>
</HEAD>
<BODY>
<P>
<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  String url="jdbc:odbc:testdb";
  //数据库名
  String user="fox";
  String password="79";
  Connection conn= DriverManager.getConnection(url,user,password);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from testtable";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  第一个字段内容为:<%=rs.getString(1)%>
  第二个字段内容为:<%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜你");%>
  <%rs.close();
  stmt.close();
  conn.close();
  %>
</P>
</BODY>
</HTML>

数据库部分我在java application中运行没有问题,请大家看一下可能是什么问题!
谢谢:)


运行后报错:
生成的 servlet 错误:
E:\mypgm\wsad\.metadata\.plugins\com.ibm.etools.server.core\tmp0\cache\localhost\server1\DefaultEAR\webtest1.war\_jsp1.java:79: 输入字符无效。
  String url="jdbc:odbc:testdb";
^
E:\mypgm\wsad\.metadata\.plugins\com.ibm.etools.server.core\tmp0\cache\localhost\server1\DefaultEAR\webtest1.war\_jsp1.java:83: 输入字符无效。
  Connection conn= DriverManager.getConnection(url,user,password);
^
^。。。。。。
24 个错误
...全文
21 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
augustfox 2004-03-30
  • 打赏
  • 举报
回复
db2驱动:是在java12目录下运行usejdbc2.bat
产生inuse文件,里面内容是jdbc 2。0
xuyingjun 2004-03-30
  • 打赏
  • 举报
回复
可以设断点执行,先看库连上了吗?连上输入信息“OK”,在执行SQL输出结果,把url在认真重新写一遍.
xuyingjun 2004-03-30
  • 打赏
  • 举报
回复
你的sqlser的驱动装了吗?看看检查一下
augustfox 2004-03-30
  • 打赏
  • 举报
回复
用的jdbc-odbc桥,我的及其单独使用jadc驱动始终会报错“no suitable driver”
re:
CoolAbu
DNS数据源设置好了
并且在java application下运行没有问题
liujs1026 2004-03-30
  • 打赏
  • 举报
回复
你用的数据库是什么?String url="jdbc:odbc:testdb"; 这个好像没见过啊
如果是oracle:
String url="jdbc:oracle:thin:@localhost:1521:数据库名";
如果是sqlserver:
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";//mydb是数据库名
CoolAbu 2004-03-30
  • 打赏
  • 举报
回复
String url="jdbc:odbc:testdb"; //你有testdb这个DNS数据源么?ODBC中设置了?
Arias 2004-03-30
  • 打赏
  • 举报
回复
String url="jdbc:odbc:testdb";
数据库的url写法有点问题,
应该这样:String database = "jdbc:oracle:thin:@192.168.91.66:1521:macaudb";
你可以试一试!
winkyTan 2004-03-30
  • 打赏
  • 举报
回复
添加一些必要的包
如:java.sql.*;
augustfox 2004-03-30
  • 打赏
  • 举报
回复
谢谢 bravowell
果然是这个问题啊
:)
谢谢大家帮忙
bravowell 2004-03-30
  • 打赏
  • 举报
回复
因为你这些行最前面存在非法字符(你看不到,看上去是空格,其实不是),你把有问题的行最前面的“空格”去掉就可以了。
augustfox 2004-03-30
  • 打赏
  • 举报
回复
本来我是用websphere的
刚才装了一个Jbuilder运行,代码如下
<%@ page language="java" contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*"%>

<HTML>
<BODY>
<P>

<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  String url="jdbc:odbc:testdb";
  //数据库名
  String user="fox";
  String password="79";
  Connection conn= DriverManager.getConnection(url,user,password);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from testtable";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  第一个字段内容为:<%=rs.getString(1)%>
  第二个字段内容为:<%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜你");%>
  <%rs.close();
  stmt.close();
  conn.close();
  %>

</P>
</BODY>
</HTML>
还是有错:
"jsp1.jsp": Error #: 100 : illegal character at line 10
"jsp1.jsp": Error #: 100 : illegal character at line 10
"jsp1.jsp": Error #: 206 : malformed expression at line 9
"jsp1.jsp": Error #: 100 : illegal character at line 11
"jsp1.jsp": Error #: 100 : illegal character at line 11
"jsp1.jsp": Error #: 100 : illegal character at line 12
"jsp1.jsp": Error #: 100 : illegal character at line 12
"jsp1.jsp": Error #: 206 : malformed expression at line 10
"jsp1.jsp": Error #: 100 : illegal character at line 13
"jsp1.jsp": Error #: 100 : illegal character at line 13
"jsp1.jsp": Error #: 206 : malformed expression at line 11
"jsp1.jsp": Error #: 100 : illegal character at line 14
"jsp1.jsp": Error #: 100 : illegal character at line 14
"jsp1.jsp": Error #: 206 : malformed expression at line 13
"jsp1.jsp": Error #: 100 : illegal character at line 15
"jsp1.jsp": Error #: 100 : illegal character at line 15
"jsp1.jsp": Error #: 206 : malformed expression at line 14
"jsp1.jsp": Error #: 100 : illegal character at line 16
"jsp1.jsp": Error #: 100 : illegal character at line 16
"jsp1.jsp": Error #: 206 : malformed expression at line 15
"jsp1.jsp": Error #: 100 : illegal character at line 17
"jsp1.jsp": Error #: 100 : illegal character at line 17
"jsp1.jsp": Error #: 206 : malformed expression at line 16
"jsp1.jsp": Error #: 100 : illegal character at line 18
"jsp1.jsp": Error #: 100 : illegal character at line 18
"jsp1.jsp": Error #: 206 : malformed expression at line 17
"jsp1.jsp": Error #: 100 : illegal character at line 24
"jsp1.jsp": Error #: 100 : illegal character at line 24
"jsp1.jsp": Error #: 206 : malformed expression at line 23
"jsp1.jsp": Error #: 100 : illegal character at line 25
"jsp1.jsp": Error #: 100 : illegal character at line 25
"jsp1.jsp": Error #: 206 : malformed expression at line 24
"jsp1.jsp": Error #: 100 : illegal character at line 26
"jsp1.jsp": Error #: 100 : illegal character at line 26
"jsp1.jsp": Error #: 206 : malformed expression at line 25
真是不知道怎么回事啊:(
CoolAbu 2004-03-30
  • 打赏
  • 举报
回复
<%@ page language="java" contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*"%>

你把这两句放到页的最顶端。
wandou999 2004-03-30
  • 打赏
  • 举报
回复
没抛异常!!
wandou999 2004-03-30
  • 打赏
  • 举报
回复
加入import java.sql.*;即可!!!

81,092

社区成员

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

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