java 怎样 加载 sql server 2005 驱动程序

 我来答
匿名用户
2017-08-24
展开全部
java 怎样 加载 sql server 2005 驱动程序
源代码:

<%@ page language="java" contentType="text/html;
charset=gb2312"%>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>Myfirst Jsp
</title>
</head>
<body bgcolor="yellow">
<%
Connection con;
Statement sql;
ResultSet rs;
try{

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(Exception e){
out.println(e);
}
try{
String
url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test";
String user="sa";
String password="saa";
con=DriverManager.getConnection(url,user,password);
sql=con.createStatement();
rs=sql.executeQuery("select *
from fruit");
while(rs.next()){
out.println(rs.getString("name"));
out.println(rs.getString("price"));
}

}catch(SQLException e){
out.println(e);
}
%>
</body>
</html>

相关问题解决:

出现的问题1:

在MyEclipse中的database Explorer连接sql server2008,出现如下错误:
Error while performing database login
with the SQLServer2008 Conn
driver:通过端口1433连接到主机localhost的TCP/IP连接失败。错误:“Connection
refused:connect.请验证连接属性,并检查SQL
Server的实例正在主机上运行,且在此端口接受TCP/IP连接,还要确保防火墙没有阻止到此端口的TCP连接。”

解决方法:

打开开始—程序—Microsoft SQL Server 2005—配置工具—SQL
Server Configuration Manager-- SQL Server 2005网络配置—MSSQLSERVER的协议,
然后右边窗口有个TCP/IP协议,点右键“启用”.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式