当前位置:数据库 > SYBASE >>

jtree sybase的连接的问题。。。

代码用的是这样的,但是报了java.sql.SQLException: JZ0BT: 类型 TYPE_FORWARD_ONLY 的 ResultSets 不支持 relative(int) 方法。的错误; package jtree; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class Main2 extends JFrame { private static Connection con; private static Statement ste = null; ResultSet rs; // 连接数据库 static { String driver = "com.sybase.jdbc2.jdbc.SybDriver"; String connection = "jdbc:sybase:Tds:127.0.0.1:2638/yongyiGdzc?charset=cp936"; // 数据库用户名 String user = "dba"; // 数据库密码 String password = "sql"; try { Class.forName(driver); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { con = DriverManager.getConnection(connection, user, password); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { //ste = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ste = con.createStatement(); } catch (SQLException e) { // TODO Auto-generated catch block // e.printStackTrace(); } } Main2() { DefaultMutableTreeNode node = new DefaultMutableTreeNode("root"); createNodes(node, "0"); JTree tree = new JTree(node); add(tree); setSize(200, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] argv) throws Exception { new Main2(); } public void createNodes(DefaultMutableTreeNode parent, String ParentID) { DefaultMutableTreeNode temp = null; String strsql = "select Unitid,unitname,companyname from Unit where companyname ='" + ParentID + "'"; // 光标的相对位置 int i = 0; try { rs = ste.executeQuery(strsql); while (rs.next()) { i++; temp = new DefaultMutableTreeNode(rs.getString("unitname")); parent.add(temp); String gj=rs.getString("Unitid"); createNodes(temp, gj); System.out.println(""+gj+"--------"+i); rs = ste.executeQuery(strsql); // 重新定位光标 rs.relative(i); } } catch (Exception e) { System.out.println(e); } } }
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,