[java]代码库
package com.csair.CSMonitor.system.user.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author yinqingsheng
*
* Create on 2012-12-31 上午9:15:27
*
* function:获取sybase数据库连接
*/
import com.sybase.jdbc3.jdbc.SybDriver;
public class SybaseConnection {
public static Connection conn = new SybaseConnection().getConnection();
public static PreparedStatement pStatement;
public static ResultSet rSet;
public Connection getConnection() {
String driverClass = "com.sybase.jdbc3.jdbc.SybDriver";
String url = "jdbc:sybase:Tds:xxx.xxx.xxx.xxx:5000/et_dcs?charset=cp936";
String username = "username";
String password = "password";
try {
SybDriver sybDriver = (SybDriver)Class.forName(driverClass).newInstance();
Connection connection = DriverManager.getConnection(url, username,
password);
return connection;
} catch (Exception e) {
System.out.println("sybase数据库连接异常!" + e);
}
return null;
}
public static void closeConnection(){
if (rSet!=null) {
try {
rSet.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (pStatement!=null) {
try {
pStatement.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (conn!=null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/*test succeed
public static void main(String[] args) throws SQLException{
if (new SybaseConnection().getConnection()!=null) {
System.out.println("success");
}else {
System.out.println("failed");
}
String sql = "select * from csmonitor_user where username=?";
PreparedStatement pStatement = conn.prepareStatement(sql);
pStatement.setString(1, "111");
ResultSet rs = pStatement.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("username") + "---->" + rs.getString("password"));
}
}*/
}
高级设计师
by: 神马 发表于:2013-08-28 21:55:06 顶(0) | 踩(0) 回复
sybase
很高级的样子
网友回复
回复yinqingsheng : 求别黑,职场新人一枚
顶(0) 踩(0) 2013-08-29 11:40:27
回复评论