请给我一个Jsp用JDBC连接SQL Server的例子,越简单越好.多谢了.(100分)

W

wukw

Unregistered / Unconfirmed
GUEST, unregistred user!
去年学了一点Jsp,可是现在转VC了.Jsp忘光了,也没那个本事.
各位大侠帮忙给我一个例子,多谢~~~
wukw@263.net.cn
 
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://yourhostname:1433;DatabaseName=NorthWind";
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from employees";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

 
谢谢楼上,可是好像不行...
<2002-12-10 下午04时54分53秒> <Notice> <WebLogicServer> <Started WebLogic Admin
Server "myserver" fordo
main "mydomain" running in Development Mode>
<2002-12-10 下午04时54分58秒> <Info> <NT Performance Pack> <Allocating: '2' NT r
eader threads>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: init>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: param verbose initialized to: true>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: param packagePrefix initialized to: jsp_servlet>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: param compilerclass initialized to: javac>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: param srcCompiler initialized to weblogic.jspc>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: param superclass initialized to null>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: param workingDir initialized to: C:/bea/wlserver6.1/config/
mydomain/applications/weather/WEB-INF/_tmp_war_myserver_myserver_weather>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: param pageCheckSeconds initialized to: 1>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: initialization complete>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] *.jsp: pageCheckSeconds over-ruled in JSPServlet to : 1>
<2002-12-10 下午04时54分58秒> <Info> <HTTP> <[WebAppServletContext(6143874,weath
er,/weather)] Generated java file: C:/bea/wlserver6.1/config/mydomain/applicatio
ns/weather/WEB-INF/_tmp_war_myserver_myserver_weather/jsp_servlet/__jdbc.java>
<2002-12-10 下午04时59分43秒> <Info> <Management> <Configuration changes fordo
m
ain saved to the repository.>
然后就挺住不动了...
 
以上代码在JBuilder7+Weblogic/tomcat下通过,你的问题应该是开发环境的配置或应用发布的问题。
 
楼上大哥,那看看是什么问题啊?
是环境有问题吗?
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
737
import
I
顶部