蔡鸟问题,怎么连接数据库?

咖啡 2003-08-21 05:03:00
初学JSP,大家别笑我,最好能写个例子。
...全文
24 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dike103 2003-08-21
  • 打赏
  • 举报
回复
把sql server 2000 的jdbc的msutil.jar,msbase.jar,mssqlserver.jar这三个文件拷到应用服务器的lib目录
<%@ page import="java.sql.*" %>
<html>
<body>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:sqllink","sa","");
//sqllink是要用ODBc设置的DSN链接,你要改成自己的实际值,用户名和密码也是一样
Statement stmt=con.createStatement();
String SQL=new String();
SQL="select top 10 productname from products";
ResultSet rs=stmt.executeQuery(SQL);
String name=new String();
while (rs.next()){
name=rs.getString("productname");
out.println(name+"<br>");
}
rs.close();
stmt.close();
con.close();
%>
</body>
</html>
咖啡 2003-08-21
  • 打赏
  • 举报
回复
谢谢各位了
Geranium 2003-08-21
  • 打赏
  • 举报
回复
<% Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
String url = "jdbc:db2:test" ;
String username = "db2admin" ;
String password = "111" ;
Connection con = DriverManager.getConnection(url ,username ,password );
%>
给你个代码,不过还是要你自己看书。要有点java基础。
Debian 2003-08-21
  • 打赏
  • 举报
回复
用google搜索,你会学到更多

81,092

社区成员

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

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