专栏:Java、EJB &
JSP 文章编号:1206 文章类别: 转贴/改编 作者: jspfuns 加贴时间:2000-8-9 18:08:35
不需ODBC可由IP地址与端口号建立与SQLSERVER的连接
关键词:Java, JSP
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;
}
}
--------------------------------------------------------------------------------
欢迎阅读China ASP的专栏文章,需要转载请与我们联系
Copyright ©
上海聚声计算机系统工程有限责任公司 1999-2000, All Rights Reserved