编写如下jsp代码:
<%@ page contentType="text/html;charset=gb2312"language="java" import="java.sql.*,java.io.*" %>
<html>
<head>
<title>连接数据库</title>
</head>
<body>
以下是从MS SQL Sever数据库读取的数据: <hr>
<%
Connection con=null;
Class.forName("com.microsoft.jdbc.sqlsever.SQLServerDriver").newInstance();
con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlsever://192.168.0.97:1433;DatabaseName=wtest","sa","sa");
if(con==null)
out.println("Not connected");
if(con!=null)
out.println("Connection succesful!");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from book;");
while(rst.next())
{
String id=rst.getString("bookID");
out.println(id);
String name=rst.getString("bookName");
out.println(name);
String publisher=rst.getString("publisher");
out.println(publisher);
int price=rst.getInt("price");
out.println(price);
out.println("<br>");
}
//关闭连接、释放资源
rst.close();
stmt.close();
con.close();
%>
</body>
</html>注:192.168.0.97是我的服务器,其上有数据库wtest,wtest中有表book(bookID varchar(20),bookName varchar(20),publisher varchar(50),price int)
我用的环境是eclipse3.2+myeclipse5.0+tomcat5.0.30
安装了Microsoft SQL Server Driver forJDBC SP3
SQL Server打了补丁SP4.程序运行后出现以下错误:
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlsever.SQLServerDriver真是不好意思,没有分给各位高手了,恳请各位帮忙,这个问题困扰我好几天了。
请高手多多指教!谢谢!
<%@ page contentType="text/html;charset=gb2312"language="java" import="java.sql.*,java.io.*" %>
<html>
<head>
<title>连接数据库</title>
</head>
<body>
以下是从MS SQL Sever数据库读取的数据: <hr>
<%
Connection con=null;
Class.forName("com.microsoft.jdbc.sqlsever.SQLServerDriver").newInstance();
con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlsever://192.168.0.97:1433;DatabaseName=wtest","sa","sa");
if(con==null)
out.println("Not connected");
if(con!=null)
out.println("Connection succesful!");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from book;");
while(rst.next())
{
String id=rst.getString("bookID");
out.println(id);
String name=rst.getString("bookName");
out.println(name);
String publisher=rst.getString("publisher");
out.println(publisher);
int price=rst.getInt("price");
out.println(price);
out.println("<br>");
}
//关闭连接、释放资源
rst.close();
stmt.close();
con.close();
%>
</body>
</html>注:192.168.0.97是我的服务器,其上有数据库wtest,wtest中有表book(bookID varchar(20),bookName varchar(20),publisher varchar(50),price int)
我用的环境是eclipse3.2+myeclipse5.0+tomcat5.0.30
安装了Microsoft SQL Server Driver forJDBC SP3
SQL Server打了补丁SP4.程序运行后出现以下错误:
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlsever.SQLServerDriver真是不好意思,没有分给各位高手了,恳请各位帮忙,这个问题困扰我好几天了。
请高手多多指教!谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货