中国开发网: 论坛: 资源共享: 贴子 345639
wynnhjg: test DS
package ds.test;

/**
* @author wynnhjg
* manage the jdbc resource
*/

import java.sql.*;


public class DatabaseConn {
/**
* get the jdbc Connection
*/

static public Connection getConnection() {

String classforname = "net.sourceforge.jtds.jdbc.Driver";

String url ="jdbc:jtds:sqlserver://195.204.140.95:1433;DatabaseName=bemsdb";

String user = "sa";
String pwd = "cmbc";

try {
Class.forName(classforname);
Connection conn = DriverManager.getConnection(url, user, pwd);
return conn;
} catch (java.lang.ClassNotFoundException e) {
System.err.println("get connection error!");
System.err.println(e);
} catch (java.sql.SQLException e) {
System.err.println("get connection error!");
System.err.println(e);
}

// error,return null
return null;
}

/**
* get the RDBMS Product
*/
public static String DataBaseProductName() throws SQLException {
String productName = null;
Connection conn = getConnection();
DatabaseMetaData metaData = conn.getMetaData();
productName = metaData.getDatabaseProductName();
conn.close();
return productName;

}
/**
* close the jdbc resource
*/
public static void closeAll(Connection connection, Statement statement,
ResultSet resultSet) {
if (resultSet != null) {
try {
resultSet.close();
} catch (Exception exception) {
}
}
if (statement != null) {
try {
statement.close();
} catch (Exception exception) {
}
}
if (connection != null) {
try {
connection.close();
} catch (Exception exception) {
}
}
}

}

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录