通过JDBC链接Sybase的方法

2种方法代码如下:

	public void getConnection() {
		try {
			
			//String url ="jdbc:sybase:Tds:192.168.102.100:5000/test";//通过jdbc方式连接,test为数据库名
			String url = "jdbc:jtds:sybase://192.168.102.100:5000/test";//通过jtds方式连接,test为数据库名
			
			//Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();//通过jdbc方式连接
			Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();//通过jtds方式连接
			
			Connection conn = DriverManager.getConnection(url, "sa", "");
			Statement stmt = conn.createStatement();
			String sql = "select * from bookinfo";
			ResultSet rs = stmt.executeQuery(sql);
			while (rs.next()) {
				System.out.println("id=" + rs.getString("id") + ";标题="
						+ rs.getString("title") + ";作者=" + rs.getString("author")
						+ "
"); } try { rs.close(); stmt.close(); conn.close(); } catch (Exception e) { System.out.println("数据库关闭出错"); } } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } }


 


 

你可能感兴趣的:(Sybase)