jtds 连接 sqlserver2005 设置
2012-03-07 11:09:02| 分类: Database | 标签:jtds sqlserver2005 连接 |字号大中小 订阅
//连接
//查询String connString = "jdbc:jtds:sqlserver://localhost:1433;DatabaseName=test;"; String userString = "sa"; String passwordString = "123456"; try { Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance(); theConnection = DriverManager.getConnection(connString, userString, passwordString); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); }
String sqlString = "select * from dbo.tbl"; try { Statement statement = theConnection.createStatement(); ResultSet resultSet = statement.executeQuery(sqlString); if (resultSet != null) { while (resultSet.next()) { //进行数据操作
String var1 = resultSet.getString(1);
String var2 = resultSet.getString(2);} resultSet.close(); statement.close(); } } catch (SQLException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (ProductionException e) { e.printStackTrace(); }
//sqlserver的必要设置,实例为AA
1.打开SQL Server Configuration Manager -> AA的协议 -> TCP/IP
2.右键单击启动TCP/IP,如果没有启动的话
3.双击这个TCP/IP进入属性,把IP地址中的IPAll中的TCP端口设置为1433
4.重新启动AA服务器
如果连接还有问题就将其他一些服务都重启一次