哪儿有jdbc连接sql server数据库的例子?

kind123 2002-08-16 03:22:46
我的操作系统为windows 2000 server,数据库为sql server 2000;;web服务器为weblogic 6.0;JDBC为sql server的驱动程序我已经安装上并且已经在classpath中配置成功,通过console我也配置了jdbc connection pool和data source;
现在我想写个例子访问sql server数据库,不知怎么写.当然sql server数据库我已经安装好了.
...全文
59 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
spring_cj 2002-08-19
  • 打赏
  • 举报
回复
到微软网站下载sqlserver jdbc的驱动,安装完成后看帮助,很清楚。
kind123 2002-08-19
  • 打赏
  • 举报
回复
你的用的是jdbc-odbc桥,我不想用哪个,我想用jdbc connection pool和data source;
shajie 2002-08-18
  • 打赏
  • 举报
回复
简单的注册表,下面是first.htm文件

<html>
<head>

</head>
<body>
<form name="login" method="POST" action="first.jsp">
<p align="center">
用户名:<input type="text" name="username" size="20"></p>
<p align="center">
密  码:<input type="password" name="password" size="20"></p>
<p align="center"><input type="submit" value="提 交" name="login">   
<input type="reset" value="重 写" name="reset"></p>
</form>
</body>
</html>
与之对应的first.jsp文件
<%@page import="java.sql.*"%>
<%@page contentType="text/html;charset=gb2312"%>

<%
String user1,pwd1;
user1=request.getParameter("username");
pwd1=request.getParameter("password");
%>

<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:bookserver";
String user="sa";
String password="zst";
Connection con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
String querystring="insert into userinfo(username,password) values('"+user1+"','"+pwd1+"')";
stmt.executeUpdate(querystring);
stmt.close();
con.close();
out.println("成功插入数据");

}
catch(Exception e)
{
System.err.println(" 数据插入没有成功!"+e.getMessage());
}
%>
不过首先要用sql server2000建一个数据库
bookserver是数据库名,
sa和zst是sql的超级用户名和密码!


kind123 2002-08-18
  • 打赏
  • 举报
回复
最好能用到jdbc connection pool和data source.
ggyy 2002-08-16
  • 打赏
  • 举报
回复
============ORACLE 8i============================
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@myhost:1521:orcl",
"scott", "tiger");

=============MySQL=================================
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://myhost:3306/dbname","user","passwd");

============InfoMax================================
Class.forName("com.informix.jdbc.IfxDriver");
conn = DriverManager.getConnection("jdbc:informix-sqli://myhost:1533:informixserver=myserver;user=rdtest;password=test");


============InforMix================================
Class.forName("com.informix.jdbc.IfxDriver");
conn = DriverManager.getConnection("jdbc:informix-sqli://myhost:1533:informixserver=myserver;user=rdtest;password=test");
=============SQLServer2000=========================
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://server1:1433","username","password");
///////////////////////////////////
jdbc driver download:

SQLServer:http://www.microsoft.com/sql/downloads/default.asp
MySQL:http://www.mysql.com/downloads/api-jdbc.html
Oracle:http://otn.oracle.com/software/content.html

---------------------DB2--------------------
--------------------- --------------------
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();//For Application
String url = "jdbc:db2:sample";
con = DriverManager.getConnection(url, userid, passwd);


Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();//For Applet
String url = "jdbc:db2:// "+server+":"+port+"/sample";
con = DriverManager.getConnection(url, userid, password );

81,092

社区成员

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

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