zoukankan      html  css  js  c++  java
  • JDBC数据库连接之JDBC-ODBC

    package com.pkg1;
    
    import java.sql.*;
    
    public class JdbcDemo {
        
        Connection conn = null;
        //Statement st = null;
        PreparedStatement st = null;
        
        public JdbcDemo(){
            this.init();
        }
        
        public boolean init(){
            try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //连接字符串
                this.conn = DriverManager.getConnection("jdbc:odbc:test1", "sa", "123456");  //test1 odbc中的名称
                //this.st = this.conn.createStatement();
                
            }catch(Exception e){
                e.printStackTrace();
                this.close();
                return false;
            }
    
            return true;
        }
    public int runCmd(String sql){ int ret = -1; try { this.st = this.conn.prepareStatement(sql); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if(st == null){ return ret; } try{ ret = st.executeUpdate(sql); }catch(Exception e){ e.printStackTrace(); return ret; } return ret; }
      //String sql = "select * from person where uid=?"
    public ResultSet runQuery(String sql, String uid){ ResultSet rs = null; try { this.st = this.conn.prepareStatement(sql); this.st.setString(1, uid); //设置参数 if(st == null){ return rs; } rs = st.executeQuery(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return rs; } return rs; } public void close(){ try{ if(st != null){ st.close(); } if(conn != null){ conn.close(); } }catch(Exception ex){ ex.printStackTrace(); } } }
  • 相关阅读:
    Java 时区转换(UTC+8 到 UTC 等等)
    spring 与 springmvc 的区别和定义
    字符串加密解密(Base64)
    上传视频本地预览问题
    vue 监听store中的数值
    判断对象是否为空
    正则 验证是否包含特殊字符
    js 过滤日期格式
    vue methods computed watch区别
    for + setTimeout
  • 原文地址:https://www.cnblogs.com/guanhao/p/4926144.html
Copyright © 2011-2022 走看看