侧边栏壁纸
博主头像
王小木人个人技术文章记录

这是很长,很好的一生

  • 累计撰写 141 篇文章
  • 累计创建 43 个标签
  • 累计收到 9 条评论

目 录CONTENT

文章目录

java oracle jdbc操作

王小木人个人技术文章记录
2021-05-26 / 0 评论 / 0 点赞 / 1,660 阅读 / 1,147 字

package com.test;

import java.sql.;
import java.util.
;

public class Test {
public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";//oracle 驱动jar包在安装目录D:\ORACLE\product\11.2.0\dbhome_1\oui\jlib\classes12.jar
public static final String URL = "jdbc:oracle:thin:@localhost:1521:orcl";
public static final String USERNAME = "wl";
public static final String PASSWORD = "123456";

public static void main(String[] args) {
	Connection conn = null;
	try {

		Class.forName(DRIVER);// 找到oracle驱动器所在的类
		conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		StringBuffer sql = new StringBuffer();
		sql.append("select * from t_user");
		PreparedStatement ps = conn.prepareStatement(sql.toString());
		ResultSet rs = ps.executeQuery();

		while (rs.next()) {
			for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
				System.out.print(rs.getObject(i) + "\t");
			}
			System.out.println('\n');
		}
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

}

0

评论区