java - 未在应用程序的数据库列中设置默认值

标签 java database oracle jdbc websphere

我有一个在 websphere 中运行的应用程序。我已经在服务器上配置了数据源并从jndi获取数据源。 我正在使用 Spring Jdbc,并且几个 select 语句运行得很好。

现在我有一个插入语句可以从“toad”内部成功运行,但相同的插入语句在应用程序中失败。

java.sql.SQLException: ORA-01400: cannot insert NULL into ("SCHEMA1"."XYZ"."CREATED_BY")

CREATED_BY is a VARCHAR2 (30 Byte) with DEFAULT set to 'SYS_CONTEXT ('USERENV', 'OS_USER')'

注意:我没有在插入语句中指定列。我的发言如下:

Insert into SCHEMA1.XYZ(some_column, another_column, is_active) values ('sadsf','sdfsdfsdf','Y')  

我使用 jdbcTemplate 本质上是在做:

jdbcTemplate.update(theQuery);

我正在配置我的数据源,如下所示:

<beans:bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <beans:property name="jndiName" value="jdbc/MyDatasource" />
</beans:bean>

现在我希望这来自为数据源设置 JAAS - J2C 身份验证数据时使用的用户名。

我不想指定所有可以通过每个查询轻松自动填充的审核列。任何帮助将不胜感激。

最佳答案

来自SYS_CONTEXT

Predefined Parameters of Namespace USERENV
OS_USER Operating system user name of the client process that initiated the database session.

还有

CLIENT_IDENTIFIER Returns an identifier that is set by the application through the DBMS_SESSION.SET_IDENTIFIER procedure, the OCI attribute OCI_ATTR_CLIENT_IDENTIFIER, or the Java class Oracle.jdbc.OracleConnection.setClientIdentifier. This attribute is used by various database components to identify lightweight application users who authenticate as the same database user.

SESSION_USER Database user name by which the current user is authenticated. This value remains the same throughout the duration of the session.

我不熟悉 Oracle 身份验证,但也许后者更适合您的任务。

关于java - 未在应用程序的数据库列中设置默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15434845/

相关文章:

C# 方法返回连接到不同数据库

java - 如何使用jdbc和tomcat连接MySQL数据库

java - 有没有办法让 tika 在找到匹配项后停止解析文件?

php - 连接到数据库 Symfony 4 Flex

r - 如何使用 pool 包转义 Athena database.table?

c# - 在 Oracle 数据库中插入记录应该使用什么查询语法?

java - 我应该如何使用 tnsnames 为 Java Web 应用程序配置我的 JDBC?

java - postgresql:无法使用在准备好的语句上采用查询字符串的查询方法

java - 如何通过Java访问SharePoint网站

android - SQLite 数据库最大存储容量