zoukankan      html  css  js  c++  java
  • JDBC模板

    JDBC 模板样式

    相关属性根据个人设置修改

    package project;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Properties;
    import java.io.IOException;
    import java.io.InputStream;
    
    public class jdbc {
        
        public static void main(String[] args)  {
            Connection connection = null;
            Statement stmt= null;
            
            try {
            final String URL ="jdbc:mysql://localhost:3306/onlinedb?serverTimezone=UTC&characterEncoding=utf-8" ;
             final  String USERNAME ="root";
             final String PWD="979416";
            //导入驱动加载具体的驱动类
            Class.forName("com.mysql.cj.jdbc.Driver");
                Properties info;
            //与数据库建立连接
             connection = DriverManager.getConnection(URL, USERNAME, PWD);
                //发送sql语句,执行命令
                 stmt=connection.createStatement();
                //String sql = "insert into user values(65,123456,'男')";     //增加数据库属性
                //String sql = "update info set ";             //修改数据库属性
                 String sql = "delete from info where 1=1";                  //输出数据库属性
                 
                //执行sql
                int count = stmt.executeUpdate(sql);
                //处理结果
                if(count>0) {
                    System.out.println("操作成功");
                
    
                }
            }catch (ClassNotFoundException e) {
                e.printStackTrace();
            }catch(SQLException e) {
                e.printStackTrace();
            }catch(Exception e) {
                e.printStackTrace();
            }finally {
                try {
                
                if(stmt!=null)stmt.close();
                
                if(connection!=null)connection.close();
                }catch(SQLException e) {
                    e.printStackTrace();
                }
            }
                
                
            
        }
         
        
        
        
    }
  • 相关阅读:
    认识“委托”
    程序员的修炼之道:从小工到专家(一)
    知识的使用 与 知识的内化
    VB.Net中 Module 的前世今生
    memcached
    C#知识
    Android之垂直显示TextView
    Android开发之各个语言
    Android之hint提示字体大小修改,显示完全
    Android 之计算控件颜色透明度
  • 原文地址:https://www.cnblogs.com/-xsw000/p/12520447.html
Copyright © 2011-2022 走看看