zoukankan      html  css  js  c++  java
  • jdbc select

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    public class mainclass {
    
        private static Connection getConn() {
            // String driver = "com.mysql.jdbc.Driver";
            // String url = "jdbc:mysql://localhost:3306/samp_db";
            String driver = "oracle.jdbc.driver.OracleDriver";
            String url = "jdbc:oracle:thin:@192.168.1.200:1521:tyhzyl";
            String username = "xnh";
            String password = "a123456";
            Connection conn = null;
            try {
                Class.forName(driver); // classLoader,加载对应驱动
                conn = (Connection) DriverManager.getConnection(url, username,
                        password);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return conn;
        }
    
        private static Integer getAll() {
            Connection conn = getConn();
            String sql = "select * from ZD_JB where f_jbid=?";
            PreparedStatement pstmt;
            try {
                pstmt = (PreparedStatement) conn.prepareStatement(sql);
                pstmt.setString(1, "Z35.001");
                ResultSet rs = pstmt.executeQuery();
                int col = rs.getMetaData().getColumnCount();
                System.out.println("============================");
                while (rs.next()) {
                    for (int i = 1; i <= col; i++) {
                        System.out.print(rs.getString(i) + "	");
                        if ((i == 2) && (rs.getString(i).length() < 8)) {
                            System.out.print("	");
                        }
                    }
                    System.out.println("");
                }
                System.out.println("============================");
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            System.out.println("hello jdbc.");
    
            getAll();
        }
    
    }
  • 相关阅读:
    【读书笔记】iOS-类别
    【读书笔记】iOS-特性
    【读书笔记】iOS-对象初始化
    【读书笔记】iOS-内存管理
    iOS---类方法(静态方法)和实例方法
    iOS ---Extension编程指南
    Swift学习与复习
    iOS----Xcode6或者Xcode7设置LaunchImage图标
    iOS----------使用 Xcode6或Xcode7配置.pch文件
    iOS开发----优秀文章推荐
  • 原文地址:https://www.cnblogs.com/yasepix/p/5522366.html
Copyright © 2011-2022 走看看