MSSQL/SQLSERVER 2000 2005 2008 2008R2 jar包驱动问题 一个sqlj
今天遇到非常蛋疼的问题 如下: ? 我的系统主库是postgreSQL的 另外还连接了两个MSSQL的数据库 先前客户说是2008R2的 我的系统会定时的去MSSQL的数据库同步数据到postgreSQL ? 于是我在配置文件里面两个MSSQL的配置都是 driver=com.microsoft.sqlserver.jdbc.SQLServerDriver url=jdbc:sqlserver://ip:port;database=dbname username=sa password=******
然后客户说有一台数据库的数据同步不了数据,并且数据库是MSSQL2000的 ? 我听到2000的第一反应就是以前数据库用2000的时候连接字符串和2005/2008的不一样 于是把连接字符串改成了 ? driver=com.microsoft.jdbc.sqlserver.SQLServerDriver url=jdbc:microsoft:sqlserver://ip:port;database=dbname username=sa password=****** ? 然后我记得以前2000的jar包是有3个的 不知道我现在项目里用的这个sqljdbc4.jar能连接2000的数据库不 ? 于是google搜 sqlserver2000 jar 转到了微软的 http://www.microsoft.com/en-us/download/details.aspx?id=1511 下载了一个README.TXT的文本 文本的大意是说不再提供sqlserver2000的jar下载了 然后给了一个新的下载地址 http://msdn.microsoft.com/data/jdbc ? 在里面我看到一jar支持 2000 2005 2008 2008R2 ? 于是下载下来sqljdbc_3.0.1301.101_chs.tar.gz 解压后在目录发现有两个jar: sqljdbc.jar? 和 sqljdbc4.jar 这两个jar的区别在于 sqljdbc.jar 适合jre1.5的环境 sqljdbc4.jar适合jre1.6的环境 ? ? 因为我是1.6 所以用sqljdbc4.jar ? 因为MSSQL2000的数据连接是 com.microsoft.jdbc.sqlserver.SQLServerDriver 所以我用rar打开sqljdbc4.jar查看该jar的文件结构 但是发现com.microsoft 的路径下没有jdbc这个目录 只有sqlserver这个目录 ? 我就奇怪了如果是没有jdbc这个目录,那么肯定2000是无法驱动的 然后一试 果然提示找不到驱动 ? 我就纳闷了 微软不是说了此jar包支持2000 2005 2008 2008R2么 怎么不行呢... ? 纳闷了好久 然后突然想,会不会是2000 2005 2008 2008R2的连接字符串都是一样的了呢? ? 于是我把2000的链接字符串也改成
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver url=jdbc:sqlserver://ip:port;database=dbname username=sa password=****** ? 这样就对了 ? 你妹的 原来是这样 ? ? 大家伙如果有这个问题的切忌啊... 2000 2005 2008 2008R2的链接字符串都一样了 而且只需要一个jar包就行了 ? ? 另外附上查看sqlserver2000的版本的方法 方法一: 在查询分析器中输入“Select @@Version”并运行,查看运行结果,对照便知版本。 8.00.194 -——————SQL Server 2000 RTM 方法二: 运行SQL SERVER服务管理器,在任务栏小托盘处,右键单击管理器图标,选“关于”,在弹出的窗口中,对照上面的信息便知 方法三: 在添加或删除程序中查看SQL Server的支持信息,可直接查看到版本号(具体方法略) 补充说明:SQL SERVER个人版,如果未打SP4补丁,是不会在1433端口监听的,即除本机外,其他电脑无法联入该数据库。 ? ? 再附上一个把MSSQL的表数据查询成 insert into格式的函数 ? USE [db] GO /****** Object: StoredProcedure [dbo].[proc_insert] Script Date: 12/05/2012 17:18:31 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER proc [dbo].[proc_insert] (@tablename varchar(256)) as begin set nocount on declare @sqlstr varchar(4000) declare @sqlstr1 varchar(4000) declare @sqlstr2 varchar(4000) select @sqlstr='select ''insert '+@tablename select @sqlstr1='' select @sqlstr2=' (' select @sqlstr1= ' values ( ''+' select @sqlstr1=@sqlstr1+col+'+'',''+',@sqlstr2=@sqlstr2+name +',' from (select case -- when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end' when a.xtype =127 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(20),'+a.name +')'+' end' when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end' when a.xtype =175 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end' when a.xtype =61 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end' when a.xtype =106 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end' when a.xtype =62 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),2)'+' end' when a.xtype =56 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(11),'+a.name +')'+' end' when a.xtype =60 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end' when a.xtype =239 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''''''')' + '+'''''''''+' end' when a.xtype =108 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),'+a.name +')'+' end' when a.xtype =231 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''''''')' + '+'''''''''+' end' when a.xtype =59 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),2)'+' end' when a.xtype =58 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),121)'+ '+'''''''''+' end' when a.xtype =52 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(12),'+a.name +')'+' end' when a.xtype =122 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end' when a.xtype =48 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(6),'+a.name +')'+' end' -- when a.xtype =165 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),'+a.name +')'+' end' when a.xtype =167 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''''''')' + '+'''''''''+' end' else '''NULL''' end as col,a.colid,a.name from syscolumns a where a.id = object_id(@tablename) and a.xtype <>189 and a.xtype <>34 and a.xtype <>35 and a.xtype <>36 )t order by colid select @sqlstr=@sqlstr+left(@sqlstr2,len(@sqlstr2)-1)+') '+left(@sqlstr1,len(@sqlstr1)-3)+')'' from '+@tablename -- print @sqlstr exec( @sqlstr) set nocount off end
?执行 Exec proc_insert TableName; ? 效果如下图所示 ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |