连接数据库的小问题,急救~~

不住不执 2003-11-30 05:48:04
初学jsp做SQLSERVER数据库例子练习时,出现如下错误
环境为:tomcat4.01,lib目录中有微软的3个SQL驱动程序包和j2ee.jar,j2eetools.jar
-------------------------------------


org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.


An error occured between lines: 9 and 42 in the jsp file: /dbtest.jsp

Generated servlet error:
D:\Program Files\Apache Tomcat 4.0\work\localhost\mytest\dbtest$jsp.java:92: Class org.apache.jsp.Statment not found.
Statment stmt;
^
1 error, 1 warning


------------------
代码
------------------
<%@ page info="database handler" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<html>
<body>
<%
try
{
Connection con;
Statment stmt;
ResultSet rs;

Class.forName("");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=sunone";
String user="sa";
String password="admin";

con=DriverManager.getConnection(url,user,password);
out.println("dfd");

stmt=con.createStatement();
stmt.executeQuery("INSERT INTO member(userID,password) Values('1','2')");

rs=stmt.executeQuery("SELECT userID,password from member");

out.println("<table border=1 width=400>");
while (rs.next())
{
String col1 = rs.getString(1);
String col2 = rs.getString(2);

out.println("<tr><td>" + col1 + "</td><td>" + col2 + "</td></tr>");
}
out.println("</table>");
}
catch(Exception e){
out.println(e);
}
%>
</body>
</html>
...全文
8 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
aku0708 2003-12-01
One way of connecting to a database is through the JDBC driver manager using the method DriverManager.getConnection. This method uses a string containing a URL. The following is an example of using the JDBC driver manager to connect to Microsoft SQL Server 2000 while passing the user name and password:

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://server1:1433;User=test;Password=secret");
回复
chouchy 2003-12-01
写错了,Statement不是Statment
回复
lu8088 2003-12-01
不懂,学习,我是连oracle的。
回复
sensory 2003-12-01
Statment 错误
回复
romeoyx 2003-12-01
同意quaker1234(林夕) 和 noratong(诺拉) 两位
回复
hojay2001 2003-12-01
你是否安装了sql2000的jdbc驱动?
要把安装生成的三个文件放到tomcathome\common\lib\下
回复
noratong 2003-11-30
楼上的说的对,是Statement,错误信息里面已经指示的很明确了.

仔细看错误信息.
回复
quaker1234 2003-11-30
Statment stmt;


Statement stmt;
回复
不住不执 2003-11-30
还是web.xml中需要配置什么东西吗?

回复
不住不执 2003-11-30
tomcat还需要装什么东西吗?
回复
不住不执 2003-11-30
加上了这个,还是错啊,哪位大哥快来救救兄弟啊~

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

=====
回复
ExplorerCSharp 2003-11-30
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver");
回复
不住不执 2003-11-30
呀,疯了,我看到了,忘乐点东西。。。。。
回复
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-11-30 05:48
社区公告
暂无公告