jave学习第三节代码

来源:互联网 发布:网络兼职信息网 编辑:程序博客网 时间:2024/05/20 19:31
package com.neusoft.utils;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class JdbcOracleTest {/** * @param args */public static void main(String[] args) {// 2.建立同数据库的连接// url:统一资源定位符String url = "jdbc:oracle:thin:@10.25.85.247:1521:orcl";String user = "scott";String password = "tiger";Connection con = null;Statement st = null;String sql = "select * from DEPT";String sql1 = "delete from USERTEST";ResultSet rs = null;PreparedStatement pst = null; 关闭资源try {if (rs != null) {rs.close();}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}try {if (st != null) {st.close();}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}try {if (pst != null) {pst.close();}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}try {if (con != null) {con.close();}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}