Oracle数据库连接出错

Oracle数据库连接出错——用户名密码非法

能获取到配置文件的内容,但是连接出错,错误信息如下:(用户名密码非法)

{user=jd2010, maxWait=30oo,maxActive=1o, password=jd2010,
url=jdbc:oracle:thin:@localhost:1521:xe,driver=oracle.jdbc.OracleDriver,
initialSize=5}
十月15,20207:24:31下午com.alibaba.druid.pool.DruidDataSource error
严重: init datasource error,url: jdbc:oracle:thin:@localhost:1521:xe
java.sql.SQLException: ORA-O1017: invalid username/password; logon
denied
at oracle.jdbc.driver.T4CTTloer.processError(T4CTTloer.java:45o)
at oracle.jdbc.driver.T4CTTloer.processError(T4CTTloer.java:392)
at oracle.jdbc.driver.T4CTTloer.processError(T4CTTloer.java:385)
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:938)

错误信息连接数据库的文件如下:DBUtils.class
在这里插入图片描述

package com.briup.common;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

public class DBUtils {
	private static Properties props = new Properties();
	private static DataSource ds;
	static {
		try {
			//以/开头放在src下,不以/开头,DBUtils放哪就放那
			props.load(DBUtils.class.getResourceAsStream("/db.properties"));
			System.out.println(props);
			ds = DruidDataSourceFactory.createDataSource(props);
		}catch (Exception e){
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	//每有一个请求过来就获取—次连接
	public static Connection getConnection() throws SQLException{
		return ds.getConnection();
	}
	public static void main(String[] args)throws SQLException {
		System.out.println(getConnection());
	}
	
}

配置文件如下: db.properties

在这里插入图片描述

driver=oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:xe
user=jd2010
password=jd2010
initialSize=5
maxActive=10
maxWait=3000

打开数据库登录发现用户名和密码是正确的,经检查后发现是配置文件中
username只写了user,修改为username后连接数据库成功
在这里插入图片描述

感谢您的阅读!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
import java.sql.*; public class Bc { // 声明数据库地址及驱动 private Connection conn = null; private String url = "jdbc:oracle:thin:@localhost:1521:ORCL"; private String driver = "oracle.jdbc.driver.OracleDriver"; private String user = "www"; private String password = "www"; // 主函数 public static void main(String[] args) { Bc bc = new Bc(); String sql="select * from T_USERS"; String sql1 = "insert into T_USERS values ('rrr','ooo')"; String sql2 ="update T_USERS set USERSPASSWORD = '888888888884444' where USERSNAME= 'www'"; ResultSet rs= bc.select(sql); bc.execute(sql1); bc.execute(sql2); try{ //显示查询出来的结果------------------ ResultSetMetaData rmeta = rs.getMetaData(); //获得数据字段个数 int numColumns = rmeta.getColumnCount(); while(rs.next()) { for(int i = 0;i< numColumns;i++) { String sTemp = rs.getString(i+1); System.out.print(sTemp+" "); } System.out.println(""); } } catch (Exception e) { // TODO: handle exception } } // 创建数据库连接方法 public Connection create() { try { /* 使用Class.forName()方法自动创建这个驱动程序的实例且自动调用DriverManager来注册它 */ Class.forName(driver); /* 通过DriverManager的getConnection()方法获取数据库连接 */ conn = DriverManager.getConnection(url, user, password); } catch (Exception ex) { System.out.println("数据库连接出错"); } return conn; } // 执行查询时用的方法 public ResultSet select(String sql) { Connection c = create();//获取连接对象,可以不声明 ResultSet rs = null; try { Statement st = c.createStatement();// 获取Staetment对象 rs = st.executeQuery(sql);// 执行操作 } catch (Exception e) { System.out.println("查询出错"); } return rs; } // 更新方法 public void execute(String sql) { Connection c = create();//获取连接对象,可以不声明 ResultSet rs = null; try { Statement st = c.createStatement();// 获取Staetment对象 st.executeUpdate(sql); } catch (Exception e) { System.out.println("更新出错"); } } }

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值