暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

JAVA-ORACLE-JDBA驱动六步

超人网页作坊 2021-07-10
892

JAVA JDBC六步

2021.07.10

package com.jdbcs.test01;


import com.sun.deploy.nativesandbox.comm.Response;

import sun.misc.Request;


import java.io.PrintWriter;

import java.sql.*;


public class test01 {

    public static void main(String[] args) throws SQLException {

        Statement sta = null;

        Connection conn=null;

        ResultSet r =null;

        Response response;

        try {

            //1.用反射的方法获取驱动        Class.forName("oracle.jdbc.driver.OracleDriver");

            //2.获取数据库连接(数据库官方提供的url,用户名,密码)

            conn= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","juzc","123");

            //3.获取数据库操作对象

            sta=conn.createStatement();

            //4.进行sql语句编写

            //4.1插入语句

String str = "insert into user1(user_id,user_name,password)values(seq_user.nextval,'cs','333')";

//执行更新操作

sta.executeUpdate(str);

//4.2查询语句

            String str="select user_name,password from user1";

            r=sta.executeQuery(str);

            while(r.next()){

                System.err.println(r.getString("user_name")+ r.getString("password"));

            }

            //5.如果是查询要对结果集进行处理


        } catch (ClassNotFoundException | SQLException e) {

            e.printStackTrace();

        }finally {

            //6.关闭资源

            sta.close();

            conn.close();

        }

    }

}


点击蓝字
关注我们


文章转载自超人网页作坊,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论