Oracle 10g使用笔记(不断更新中...2006年9月15日)

1.查看product/10.2.0.1/db/network/admin/tnsnames.ora文件获取实例名和listener的端口号; 

2.用JDBC向数据库中插入记录,出现以下错误:

   java.sql.SQLException: 索引中丢失  IN 或 OUT 参数

  原因一般是:在使用PreparedStatement时set参数的值不够。例如:

 PreparedStatement ps=conn.prepareStatement("insert into usertable values(?,?,?)");

 ps.setInt(2,"Li MIng");

 int k=ps.executeUpdate();

 由于第一个和第三个参数没有被赋值,所以出现上述错误;

3.用JDBC向数据库中插入记录,出现以下错误:

   ORA-01461 : 仅可以为插入LONG列的LONG值赋值 

  Google了一下,找到如下的解释:

This error occurs when there is a mismatch between the character set specification of the Oracle server and the Oracle clients. The Oracle client’s character set should be the same or subset of the Oracle server’s character set. Character sets are used to actually STORE locale-dependant data. When clients from different locales connect to the database, automatic conversion of character sets takes place in the background to display the data properly (based on the NLS_LANG setting on the client). When a client in a different locale sends data back to Oracle, same conversion takes place before data is actually stored. When the character sets on the clients and server do not match, such an error is thrown.

The Oracle server’s NLS_LANG setting can be found out as follows:

Fire the following query to get the full set of NLS settings of the database: SELECT * FROM NLS_DATABASE_PARAMETERS;
The NLS_LANG parameter is <language>_<territory>. <Characterset>
NLS_LANG=<NLS_LANGUAGE>_<NLS_TERRITORY>.<NLS_CHARACTERSET>

 
The OST4 Oracle9i has been set up with UTF8 character set. Its NLS_LANG parameter is AMERICAN_AMERICA.UTF8. However the NLS_LANG parameter for the Oracle clients on dev03 or our local machine was not set with this value. On setting NLS_LANG parameter to AMERICAN_AMERICA.UTF8 on client side, the issue got resolved.
 
To set NLS_LANG on Windows check the following entry in the registry: HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/NLS_LANG. On Unix NLS_LANG is set as a local environment variable.

        查了一下Oracle服务器端的NLS_LANG=AMERICAN_AMERICA.UTF8,于是在应用程序运行的环境中设置同样的环境变量,但问题还是没有解决。我发现在插入记录的时候如果不插入BLOB类型的字段就没有问题,我的程序是对blob字段采用preparedStatement.setBytes()的方式赋值,于是试图修改程序,采用ORACLE特有的方式对大字段赋值:

.....

conn.setAutoCommit (false);

PreparedStatement insertStmt = conn.prepareStatement("insert into blobtable (id, blobcolumn) values(1, empty_blob())");
PreparedStatement updateStmt = conn.prepareStatement("select blobcolumn from blobtable where id = 1 for update");

insertStmt.executeUpdate();
OracleResultSet rs = (OracleResultSet) updateStmt.executeQuery();

if (rs.next() )
{
OutputStream os = rs.getBLOB(1).getBinaryOutputStream();
InputStream is = filePart.getInputStream();

byte buffer[] = new byte[32765];
while ((numofbytes = is.read (buffer,0,32765)) != -1)
{
os.write(buffer, 0, numofbytes);
filesize += numofbytes;
}

is.close();
os.close();
rs.close();
}
insertStmt.close();
updateStmt.close();
conn.commit();

运行了一下,问题解决了。但感觉这种方式太麻烦了。

忽然想到可能是JDBC的问题,我以前用的是Oracle网站上下的最新的THIN JDBC,试着在这次买的Oracle的客户端管理程序目录里找到一个JDBC,最终发现使用这个JDBC程序不用修改,还是用setBytes()方式就可以正常运行。

无语......

4. 用sqlldr导入数据:

    sqlldr userid=user/password control=control_file.txt

    control_file.txt文件的样式:

load data infile '/database/oracle/temp/sysdata/ID_TABLE1.TXT' into table ID_TABLE
fields terminated by '|'
(ID_TABLE_ID,TABLE_NAME,NEXT_ID,QUANTITY)

    注意:在执行命令后,在当前目录下会出现与控制文件同名的日志文件(如control_docbaseinfo.log),此文件会标识出未成功导入的记录,而且如果出错,当前目录下还会出现与控制文件中指定的数据文件同名的.bad文件(如docbaseinfo.bad),包含未成功导入的记录。
 5.修改字段名称

1、 alter table tablename add gifurl datatype;
2、 update tablename set gifurl = jifurl;
3、 alter table tablename drop column jifurl;

 

6.导入工具imp交互式命令行方式的例子
$ imp
Import: Release 8.1.6.0.0 - Production on 星期五 12月 7 17:01:08 2001
(c) Copyright 1999 Oracle Corporation.  All rights reserved.
用户名:  test
口令:****
连接到: Oracle8i Enterprise Edition Release 8.1.6.0.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
导入文件: expdat.dmp> /tmp/m.dmp
输入插入缓冲区大小(最小为 8192 ) 30720>
经由常规路径导出由EXPORT:V08.01.06创建的文件
警告: 此对象由 TEST 导出, 而不是当前用户
已经完成ZHS16GBK字符集和ZHS16GBK NCHAR 字符集中的导入
只列出导入文件的内容(yes/no):no>
由于对象已存在, 忽略创建错误(yes/no):no> yes
导入权限(yes/no):yes>
导入表数据(yes/no):yes>
导入整个导出文件(yes/no):no> yes
. 正在将TEST的对象导入到 SCOTT
. . 正在导入表                       "CMAMENU"       4336行被导入
成功终止导入,但出现警告。

7.查看所有表

select * from tab

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值