Java 版 (精华区)
发信人: freely (<% GGStudy %>), 信区: Java
标 题: 不需ODBC可由IP地址与端口号建立与SQLSERVER的连接(转载)
发信站: 哈工大紫丁香 (2001年07月31日20:37:14 星期二), 站内信件
【 以下文字转载自 WebDev 讨论区 】
【 原文由 freely 所发表 】
JSP不需ODBC可由IP地址与端口号建立与SQLSERVER的连接
转摘自 http://www.netqu.com
package jsp;
import java.sql.*; // JDBC package
public class sql_data {
String url = "jdbc:inetdae:192.168.2.70?sql7=true"; // use your hostname and
port number here
String login = "sa"; // use your login here
String password =""; // use your password here
public Connection connection = null;
public Statement st = null;
public ResultSet rs = null;
public sql_data(){
try {
Class.forName("com.inet.tds.TdsDriver").newInstance();
DriverManager.setLoginTimeout(10);
// connection = DriverManager.getConnection(url,login,password);
// DatabaseMetaData conMD = connection.getMetaData();
// connection.setCatalog( "register");
} catch(Exception e) {
e.printStackTrace();
}
}
public void sqlclose() {
try {
st.close();
connection.close();
}catch(SQLException ex) {
System.err.println("sqlclose: " + ex.getMessage());
}
}
public ResultSet executeQuery(String sql) {
try {
connection = DriverManager.getConnection(url,login,password);
connection.setCatalog( "register");
st = connection.createStatement();
rs = st.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
--
I know i love you before i met you.
I've been waiting all my life ... ...
yours,
freely
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 天外飞仙]
--
※ 转载:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: 202.118.170.87]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.404毫秒