请问一下,谁用java写了连接远程操作sql server数据库的应用程序,怎么写,能给原码吗? 是象manage consle那样操作么??还是只是来执行几句sql语句?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先建立ODBC/** @dbbean.java* Author:nicolas* Date:2001-3-21* version:1.0v* Function:connect database,query table,update table by parameter*/package dbbean;import java.sql.*;import java.io.*;public class dbbean{//String sConnStr="jdbc:oracle:thin:@172.16.1.2:1521:labora","scott","tiger"; String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver"; Connection conn=null; ResultSet rs=null; /* * constructor:try to create a dababase driver */ public dbbean(){ try{ Class.forName(sDBDriver); }catch(java.lang.ClassNotFoundException e){ System.err.println("dbbean(): "+e.getMessage()); } } public ResultSet executeQuery(String sqlStr){ rs=null; try{ conn=DriverManager.getConnection("jdbc:odbc:wygl"); Statement stmt=conn.createStatement(); rs=stmt.executeQuery(sqlStr); }catch(SQLException e){ System.err.println("executeQuery(): "+e.getMessage()); } return rs; } public int executeInsert(String sqlStr){ try{ conn=DriverManager.getConnection("jdbc:odbc:wygl"); Statement stmt=conn.createStatement(); stmt.executeUpdate(sqlStr); return 1;//成功 }catch(SQLException e){ System.err.println("executeInsert(): "+e.getMessage()); return 0;//失败 } } public int executeUpdate(String sqlStr){ try{ conn=DriverManager.getConnection("jdbc:odbc:wygl"); Statement stmt=conn.createStatement(); stmt.executeUpdate(sqlStr); return 1;//成功 }catch(SQLException e){ System.err.println("executeInsert(): "+e.getMessage()); return 0;//失败 } } public int executeDelete(String sqlStr){ try{ conn=DriverManager.getConnection("jdbc:odbc:wygl"); Statement stmt=conn.createStatement(); stmt.executeUpdate(sqlStr); return 1;//成功 }catch(SQLException e){ System.err.println("executeDelete(): "+e.getMessage()); return 0;//失败 } }} 给nicolas(nicolas) 题个建议,一家之言,见谅.在建立一个Connection的时候,是很花费时间的,所以你的程序就有点效率不高之嫌疑.应该只建立一个Connection. 偶的一些看法:1.摒弃 ODBC,使用专用的 JDBC Driver,连接 SQL Server 本人喜欢用 i-net 的产品 可以到 http://www.inetsoftware.de/ 下载,使用方法可参考其说明文件。2.如果程序比较复杂,可以使用连接池来提高效率(前提:你的应用服务器要支持此项功能) 请问FSbaby(虫虫特工) 那里有当“JDBC Driver,连接 SQL Server ”请MAIL我。[email protected] 怎样匹配这样的字符? 过滤字段 这个统计该怎么写 多台服务器共享一个数据库,同时访问一个数据,该怎么设计?具体步骤,非常感谢,如果有视频或图片教程更好。 大家好。。有个新问题 救命啊!update时忘了写条件了,怎么恢复? 请教大家一个存储过程递归问题 请帮忙优化一条sql语句!谢谢! vfp问题,如何打印查询结果,在线急等!!! 面试考题:关于分组分类统计的sql语句写法! 初学者请教哪里有DEVELOPER/2000 在Sqlserver中存储过程中的参数怎么在Sql语句中调用
* @dbbean.java
* Author:nicolas
* Date:2001-3-21
* version:1.0v
* Function:connect database,query table,update table by parameter
*/
package dbbean;
import java.sql.*;
import java.io.*;public class dbbean{
//String sConnStr="jdbc:oracle:thin:@172.16.1.2:1521:labora","scott","tiger";
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
Connection conn=null;
ResultSet rs=null;
/*
* constructor:try to create a dababase driver
*/
public dbbean(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("dbbean(): "+e.getMessage());
}
} public ResultSet executeQuery(String sqlStr){
rs=null;
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
}catch(SQLException e){
System.err.println("executeQuery(): "+e.getMessage());
}
return rs;
} public int executeInsert(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeInsert(): "+e.getMessage());
return 0;//失败
}
} public int executeUpdate(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeInsert(): "+e.getMessage());
return 0;//失败
}
} public int executeDelete(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeDelete(): "+e.getMessage());
return 0;//失败
}
}
}
在建立一个Connection的时候,是很花费时间的,所以你的程序就有点效率不高之嫌疑.
应该只建立一个Connection.
1.摒弃 ODBC,使用专用的 JDBC Driver,连接 SQL Server 本人喜欢用 i-net 的产品
可以到 http://www.inetsoftware.de/ 下载,使用方法可参考其说明文件。
2.如果程序比较复杂,可以使用连接池来提高效率(前提:你的应用服务器要支持此项功能)
那里有当
“JDBC Driver,连接 SQL Server ”请MAIL我。[email protected]