java连接Oracle(JDBC)

复制代码
package text.coming;

import java.sql.*;

public class demo {
    public static void main(String[] args) {
        Connection ct=null;
        Statement statement=null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","tiger");
             statement=ct.createStatement();
             int n=statement.executeUpdate("insert into student values(110,'厉害','鸡你太美')");
             System.out.println("成功插入数据!");
             System.out.println("影响的行数:"+n);
        } catch (Exception e) {
            e.printStackTrace();
        }
    //关闭资源
        finally
        {
            if(statement!=null)
            {
                try {
                    statement.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                statement=null;
            }
            if(ct!=null)
            try{
            ct.close();
            }
            catch(SQLException e)
            {
            e.printStackTrace();
            }
            ct=null;//使用垃圾回收机制    
        }
        
    }

}
复制代码

 

posted @   困到很想醒  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示