用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

获取sybase数据库连接

2013-08-28 作者: yinqingsheng举报

[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"));
			
		}
	}*/

}


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...