数据库错误提示

Posted on 2008-04-23 21:50 林世军 阅读(1322) 评论(0)  编辑  收藏
 

问题1:出现ClassNotFoundException  

这个问题是由于你没有把driver类放到你的classpath中,也就是说你的程序找不到驱动类,包括三个包:msutil.jar,msbase.jar,mssqlserver.jar
--解决:jb:可以在工程属性中加入这三个包,netbean:可以把这三个包copy到某一个 lib下,也就是某个类的公共库中

问题2:出现[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket

这个错误,不论在什么 情况 下,凡是出现这种错误的,都不是程序本身的错误,因为大部分人都知道:jdbc:microsoft:sqlserver: @ /localhost:1433;这样写是对的,但为什么这样写呢

下面我们就详细的看一下 如何用jdbc连接到sqlserver2000 (引自converse斑竹的帖子
介绍连接server2000的方法之一:使用DriverManager.getConnection(...)连接到数据库有两种方法,one is :with a connection url through the jdbc driver manager,another is with a jndi datasource.

我们先说第一种:使用DriverManager.getConnection()方法
第一:你需要设置classpath,它是你 jvm加载类时所要寻找的路径。
当然首先你要有jdbs driver for sqlserver。
设置环境变量:window os:set classpath=.;${your path to save the driver}/msbase.jar;${}/mssqlserver.jar;${}/msutil.jar
第二:注册你的驱动registering the driver
注册驱动告诉你得jdbc管理器去加载什么驱动程序类,
当使用class.forName(),你必须指定驱动类名称,
com.microsoft.jdbc.sqlserver.SQLServerDriver.例如:Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
第三:在注册完一个驱动类后,你必须把你的数据库的物理信息以一个url的形式传给管理器,下面是一个url模版:jdbc:microsoft:sqlserver://server_name:port,其中server2000默认的端口号为:1433.下面是一个例子:
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://server_name:1433","userName","password");
注:这里的server_name必须是一个ip address,或者一个主机名,你可以使用ping命令来测试你的主机名是否传回一个正确的ip address
下面是 连接url的属性解释:
------------------------------------------------------------------------------
---属性----------------------------------------说明--------------
--DatabaseName(0)                   ------the name of the sql server database to which you want to connect
--HostProcess  (O)                    ------the process ID of the application connecting to SQL Serve r

2000.The supplied value 
                                            ------appears in the "hostprocess" column of the sysprocesses table.
--NetAddress(O)                    ------the MAC address of the network interface card of the 

application    connnecting to sql   . server 2000.the supplied 

value appears in the "net_address" column  of 

the sysprocesses   table.
--Password                         ------the case-insensitive password used to connect to your sql 

server database.
--PortNumber(O)                    ------the tcp 端口号(一般在使用datasource时使用)默认为:1433
--ProgramName(0)                   ------the name of the application connecting to sql server 2000,

the supplied value appears in    the "program_name" column of

 the sysprocesses table .
--SelectMethod                     ------SelectMethod={cursor|direct}.determines wherther database

 cursors   are used for select  statements .performance and behavior 

of the driver are affected by 

the selectMethod .                                           

-------setting.Direct:        -------- the direct method sends the complete results set in one request 

to the   driver .it is useful for queries that only produce a small amount of 

data that you fetch   completely,you should avoid using direct when 

executing queries that produce a large 

amount of   data,as the result set is cached completely on the client 

and constrains memory .In this mode,each   statement requires its

 connection to the database.this is accomplished by 

cloing connections .

------- cloned               connections use the same connection properties as the 

original connection;however,because transactions   occur on a 

single connection,auto commit mode is required,Due to this,JTA is 

not supported in direct mode.In   addition,some operations,such as 

updating an insensitive result set,are not supported in direct mode 

because driver create a second statement internally.Exceptions 

generated due to the creation of cloned statements usually return 

an error message similar to "Cannot start a cloned connection while 

in manual transaction mode"
----Cursor:           ------ when the selectMode is set to cursor ,a server-side cursor is generated 

行被 的方式提取出来,JDBC语句setFetchSize这时候就起作

用了,它可以控制每次提取的行数,cursor值在查询结果产生大量数

据的时候非常有用,并且也用在jta中,但是setFetchSize具体设置

多大,这是没有什么规则的, 只能通过 多多尝试 找到一个合理的值。

--解决:启动你的sqlserver2000的服务器网络实用工具后,确保你的Tcp/Ip协议已启动,默认的应该都启动了,这是进行通讯的条件一
然后,在选中Tcp/Ip协议后点击属性,就看到了一个默认端口号,这就是你在 getConnection里用到的端口号,你必须把你程序里用
到的端口号,写成这里的值,这样才能解决上面的问题,当然你也可以在这里把端口号给该了,而保持程序不变!

问题3:有些时候也连接上了,但就是不能访问,或者提示说sql语句有错误
--解决:这些都是管理sqlServer2000所需要注意的,或许你没有给这个用户分配足够的权限,或者你的sql语句中用到了sqlserver里保留的
关键字,我就遇到了这样一个问题:我写了个 select * from USER这个语句怎么执行都不对,后来看了分析器,才知道这是一个关键字,你不可以用它来命名的!
错误:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode. 
A: 这个错误产生的原因一般是当你在一个SQL SERVER的JDBC连接上执行多个STATEMENTS的操作,或者是手动事务状态(AutoCommit=false) 并且使用 direct (SelectMethod=direct) 模式. Direct 模式是默认的模式. 
解决办法
当你使用手动事务模式时,必须把SelectMethod 属性的值设置为 Cursor, 或者是确保在你的连接上只有一个STATEMENT操作。

问题4: java.sql.SQLException

A: 这个错误产生的原因一般是当你在一个SQL SERVER的JDBC连接上执行多个STATEMENTS的操作,或者是手动事务状态(AutoCommit=false) 并且使用 direct (SelectMethod=direct) 模式. Direct 模式是默认的模式. 
解决办法
当你使用手动事务模式时,必须把SelectMethod 属性的值设置为 Cursor, 或者是确保在你的连接上只有一个STATEMENT操作

问题5:xp下 出现[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket

A: 在WinXP sp2下,sqlserver 不能用jdbc,下载 sql server sp3,下载jdbc sp3的驱动,装上以后就正常了 下载Microsoft  SQL  Server  2000  Service  Pack  3a并安装,SQL请选用混和安装模式 下载SQL  Server  2000  Driver  for  JDBC  Service  Pack  3   并安装。

另外一种解决办法:本机 的SQL Server 2000 当客户端,直接连接到主机(Windows XP)上的SQL Server 2000数据库,也就是在 本机 上新注册一个SQL Server,指向服务器上的SQL Server。这样再运行一下原来的Java 程序就不会出现Error establishing socket这个错误了

问题6: Microsoft JDBC "ResultSet Can Not Re-Read Row Data" Error

A: 使用MS SQL Server 2000 SP3a/SP4做数据库服务器时,用Microsoft提供的JDBC驱动(2.2.0040),在查询时遇到一个SQLException
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column # 查询语句和JDBC代码都没有问题,怀疑是Microsoft驱动的BUG,google一下果然在Microsoft support站点发现了问题: http://support.microsoft.com/kb/824106 原因是如果该表存在TEXT, NTEXT, IMAGE等大型字段,对于ResultSet的字段读取必须按照从左向右读,如果你用:
int a = rs.getInt(2);
int b = rs.getInt(1);
则报错。Microsoft给出的方案是不能从右往左也不能连续读2次。没办法自己改代码,严格从左向右读,结果就没有问题了。

问题7: 当oracle procedure中使用了事务时,jta的事务不起作用

A: 用jdbc调用存储过程,存储过程中最好不要有事务,除非所有的数据库操作都在存储过程中完成 如果存储过程中有事务,该事务能提交或回滚本次同数据库会话中进行的所有操作。包括在程序中进行的还没有提交的操作 无论在jta还是在存储过程中的事务,其控制的对象都是同数据库的会话,所以其本质是一样的。

问题8: 连接池 不断增加直至weblogic down机

A: 应该是程序建立连接的方式和关闭方式不当造成的 可以在连接池设置一下Inactive Connection Timeout

问题9: SQL的服务自动停止的问题

A 错误原因 :
线程试图对一个虚地址进行读或写,但没有做适当的存取。
解决方法  
注意:从  SP3  安装  CD  或安装目录运行以下命令。在下面的步骤中,安装目录是  C:\sql2ksp3

1.  在命令提示符处,运行以下命令,将  CAB  格式的自解压文件  SQLRedis.exe  中的文件解压缩到  C:\Extract  文件夹中:
C:\sql2ksp3\x86\other\sqlredis.exe /T:C:\Extract /C
注意: SQLRedis.exe  文件位于安装目录中的  \x86\Other  文件夹中。  
2.   C:\Extract  文件夹中找到  Mdac_qfe.exe  文件,然后运行  Mdac_qfe.exe  文件。  
3. “Microsoft Data Access Components Hotfix Installer” 对话框打开,显示出您正在安装修复程序。单击 确定 ,继续安装修复程序。   
4.  成功安装  MDAC  修复程序  (Mdac_qfe.exe)  后,再次运行  SQL Server 2000 SP3  安装程序,成功完成安装。

问题 10 DB2的type4驱动程序一直出现如下的错误:com.ibm.db2.jcc.a.DisconnectException: encoding not supported

A: 在建立Database时,必需选UTF-8的编码,如果选用Big5时会出现encoding not supported的错误。DB2的JDBC 只支持UTF-8的编码方式。解决方法也就是用不同的字符集创建数据库
db2 drop db userdb
export LANG=en_US.iso88591
db2 create db userdb

问题11:jb2005与mysql连接报错 com.borland.dx.dataset.DataSetException: The URL: jdbc:jdbc:mysql://localhost/mydata could not be found.  Check for misspellings, and that the right driver is present on the classpath

A: 配置Tools-->Enterprise  Setup-->Database  Drivers-->Add,加入User  Home/mysql
后,要重新启动一下你的JBuilder才可以的。

问题12:oracle存取blob字段出现 ORA-01002:fetch out of sequence 错误

A: 1.禁用自动提交试试。如果你仍然有其他的行在查询的时候也禁用手工提交,当有for update游标仍然打开时执行的任何提交可能会造成这个错误。
setAutoCommit(false)
2.升级补丁
Versions Affected
This problem affects Oracle versions: 
8.1.7.3 and 8.1.7.4 
9.0.1.3 
9.2.0.1 (Base Release) 
The problem does NOT affect: 
Versions prior to and including 8.1.7.2 
9.0.1.0 to 9.0.1.2 inclusive 
9.0.1.4 
9.2.0.2 onwards (not available at time of writing)

问题13: 喆、娗、奭、珺、旻、奭、旻 怪异字符插不进 informi x 数据库

A: GBK不是标准字符集 除了GB2312,你可以试试GB18030,如果支持GB18030那什么中文字符都能插入

问题14: Jbuilder连接interbase数据库 提示[interclient][interbase]connection rejected by remote interface

A: 是不是客户端和服务端版本不一致 ;防火墙导致;登录用户的权限是否足够。

问题15: SQL Server 的身份验证模式改不过来怎么办

A: 企业管理器-〉新建SQL注册,看看帮助文档

问题16:  weblogic server定义连接连接池,测试连接时总是提示找不到类路径

A:将类文件放在 server\lib下,然后在server\bin\setWLSEnv.cmd中将他们添加进去

问题17: JDBC Connection Pool 测试出现异常 Warning! Connectivity to backend database not verified. This is either because required connection pool attributes "TestConnectionsOnReserve" or "TestConnectionsOnRelease" have not been enabled, or an invalid value has been specified for attribute "TestTableName". Please check the server log for more details

A: weblogic的控制台中,配置pool完毕后 选择Test Reserved Connections 、 Test Released Connections选项; 另外要指定 测试要连接的表的名称

问题18: 为了复用Connection,我在excute()方法的开始部分取得连接,在结束时释放Connection。在excute()方法中将Connection传递给DAO进行数据库操作。请问这样做有什么缺陷,应该怎样做?从DataSource中取Connection是个很耗时的操作吗?

A: 最好不要 这样做 ,从服务器的connection pool 中获取连接时间很短,大概是1%秒的样子,所以用了就释放最好了,不会引起connection leak

[截至帖子2005-8-29]


只有注册用户登录后才能发表评论。


网站导航:
 

posts - 4, comments - 0, trackbacks - 0, articles - 2

Copyright © 林世军