Caused by: java.sql.SQLException: ORA-01017: invalid username/password; logon denied
时间: 2023-11-21 08:57:43 浏览: 44
这个错误通常是由于用户名或密码不正确导致的。请确保您输入的用户名和密码是正确的,并且与您连接的数据库相匹配。如果您确定您的用户名和密码是正确的,那么可能是您的数据库配置有问题。您可以检查您的数据库配置文件,确保它们与您的数据库匹配。如果您使用的是Spring框架,您可以检查您的数据源配置是否正确。以下是一个Java连接Oracle数据库的示例代码:
```java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class OracleJDBC {
public static void main(String[] argv) {
System.out.println("-------- Oracle JDBC Connection Testing ------");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("Oracle JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe", "username",
"password");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
}
}
```