![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
java 怎样 加载 sql server 2005 驱动程序
1个回答
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协议,点右键“启用”.
源代码:
<%@ 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协议,点右键“启用”.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询