qiek(原作)
據說微軟提供的jdbc驅動不支持
在Win
寫類時注意
另CLASS_PATH中必須加入jtds
/*
* Author:liufei
* Homepage:
* Copyright
*/
import java
import java
class Sql {
public static void main(String[] args) {
try{
String query=
String URL=
Class
Connection conn=DriverManager
Statement stmt=conn
ResultSet rs=stmt
int i=
for(i=
rs.next();
System.out.println(rs.getString(1));
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
用JSP連接:
必須將jtds.jar放至WEB-INF/lib目錄下
test.jsp內容如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
String url="jdbc:jtds:sqlserver://135.0.0.2:1433/Northwind;USER=sa;PASSWORD=webserver";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from Orders";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一個字段內容為: <%=rs.getString(1)%>
您的第二個字段內容為: <%=rs.getString(2)%>
<%}%>
<%out.print("數據庫操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26483.html