java.sql.SQLException: ORA-00918: 未明确定义列ORA-00918

本文讨论了在使用Oracle SQL时遇到的ORA-00918异常,该异常通常由重复列名引起。通过示例代码演示了如何修改查询语句以解决此问题,并确保数据库操作正确执行。

转自:http://www.javabrother.net/viewthread.php?tid=3447

java.sql.SQLException: ORA-00918: 未明确定义列ORA-00918, 异常,

Oraclejava.sql.SQLException: ORA-00918: 未明确定义列

大概就是报的这个异常,意思就是有两个或者多个相同的列,Oracle它不知道怎么办,所以就报这个异常,希望你去解决,^_^

 

select b.id,b.customname, datadescription as cusType,b.customcode, datadescription as cusState from cstcustom b left join sysdictionary c on b.customstate = c.dataid and c.datatypecode = 'CustomState' left join sysdictionary d on b.customtypeid = d.dataid and d.datatypecode = 'CustomType' where b.customstate != 2


改过后:

 

select b.id,b.customname, d.datadescription as cusType,b.customcode, c.datadescription as cusState from cstcustom b left join sysdictionary c on b.customstate = c.dataidand c.datatypecode = 'CustomState' left join sysdictionary d on b.customtypeid = d.dataid and d.datatypecode = 'CustomType' where b.customstate != 2


就OK了!

当在 Java 中出现 `java.sql.SQLException: ORA-28001: the password has expired` 错误,意味着连接的 Oracle 数据库用户密码已过期。可以通过以下方法解决: ### 修改密码有效期 可以通过 SQL 语句查看密码有效时间(一般是 180 天),使用如下语句: ```sql select * from dba_profiles where profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME'; ``` 若要修改密码有效期为无限制,可使用以下语句: ```sql ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; ``` ### 重置用户密码 可以使用 SQL 语句重置用户密码,示例如下: ```sql ALTER USER username IDENTIFIED BY new_password; ``` 其中 `username` 是数据库用户名,`new_password` 是新设置的密码。 ### 在 Java 代码中处理 在 Java 代码中捕获 `SQLException`,当出现 `ORA - 28001` 错误时,提示用户更新密码并重新连接。示例代码如下: ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class OracleConnectionExample { public static void main(String[] args) { String url = "jdbc:oracle:thin:@localhost:1521:orcl"; String username = "your_username"; String password = "your_password"; try { Connection connection = DriverManager.getConnection(url, username, password); System.out.println("Connected to the database!"); } catch (SQLException e) { if (e.getErrorCode() == 28001) { System.out.println("Password has expired. Please update your password."); // 这里可以添加更新密码的逻辑 } else { e.printStackTrace(); } } } } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值