java连接sysbase例子

1、首先下载驱动。。我在官网上没找到。后来直接在google里面搜索java连接sysbase驱动下载。

最后还是在CSDN上直接下载了它的jar文件jconn3d.jar。

 

 

2、源代码如下:

 

 

package testSysbase;

import com.sybase.jdbc3.jdbc.SybDriver;
import java.sql.*;
import java.io.*;
import java.util.*;

public class TestSybase {
	public static void main(String[] args) {
		try {
			Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
			String url = "jdbc:sybase:Tds:172.16.140.151:5000/blue";// blue为数据库名
			Properties sysProps = System.getProperties();
			sysProps.put("user", "uareport"); // 设置数据库访问用户名
			sysProps.put("password", "uareport"); // 密码
			Connection conn = DriverManager.getConnection(url, sysProps);
			Statement stmt = conn
					.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
							ResultSet.CONCUR_UPDATABLE);
//			String sql = "select  * from iApplicationStat where Application like 'UA%' and Time>='08:00:00' and Time<='20:00:00' "; 
			String sql = "select  * from iApplicationStat where Application like 'UA%' and Timestamp between '2012-02-22 00:00:00' and '2012-02-22 23:59:59'  "; 
			ResultSet rs = stmt.executeQuery(sql);
			while (rs.next()) {
				System.out.println(rs.getString(2)); // 取得第二列的值
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}
 

 

refurl:http://blog.csdn.net/donnyfox/article/details/465209

 

你可能感兴趣的:(java)