侧边栏壁纸
博主头像
王小木博主等级

这是很长,很好的一生

  • 累计撰写 124 篇文章
  • 累计创建 39 个标签
  • 累计收到 3 条评论

目 录CONTENT

文章目录

java oracle jdbc操作

王小木
2021-05-26 / 0 评论 / 0 点赞 / 191 阅读 / 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

评论区