采用的是第三方的jtds-1.2.5.jar驱动,如下:
public class JdbcConnSybase { public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { // Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();//通过jdbc方式连接 Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance(); // 通过jtds方式连接 // String url // ="jdbc:sybase:Tds:192.168.102.100:5000/test";//通过jdbc方式连接,test为数据库名 String url = "jdbc:jtds:sybase://192.9.190.98:4100/inner_dbs";// 通过jtds方式连接,test为数据库名 conn = DriverManager.getConnection(url, "emp", "empemp"); stmt = conn.createStatement(); String sql = "select * from lps_mst"; rs = stmt.executeQuery(sql); int i=1; while (rs.next()) { System.out.println("(" + i++ + ")" + "pan:" + rs.getString("pan")); } } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }finally { rs = null; } try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); }finally { stmt = null; } try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }finally { conn = null; } } } }?