我有一个在 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 身份验证数据时使用的用户名。
我不想指定所有可以通过每个查询轻松自动填充的审核列。任何帮助将不胜感激。
最佳答案
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/