zoukankan      html  css  js  c++  java
  • 2021/4/5

    1.今日收获内容
    在web链接数据库

    package DBUtil;
    
    
    import java.sql.*;
    
    
    public class DBUtil {
    
        public static String db_url = "jdbc:mysql://localhost:3306/text111?serverTimezone=GMT%2B8&useSSL=false";
        public static String db_user = "root";
        public static String db_pass = "zgq727";
    
        public static Connection getConn () {
            Connection conn = null;
    
            try {
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection(db_url, db_user,db_pass);
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            return conn;
        }//end getConn
    
        public static void close (Statement state, Connection conn) {
            if (state != null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
    
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
        public static void close (ResultSet rs, Statement state, Connection conn) {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
    
            if (state != null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
    
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
        public static void main(String[] args) throws SQLException {
            Connection conn = getConn();
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            
            String sql ="select * from text2";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            if(rs.next()){
                System.out.println("连接成功");
            }else{
                System.out.println("连接失败");
            }
        }
    }

    连接到数据库

    2.遇到的问题
    链接无误

    3.明天目标

    Javasql

  • 相关阅读:
    xib中Autolayout的使用
    duplicate symbol _gestureMinimumTranslation in:
    oracle数字字符串是否有非法数字
    ora-01536 space quota exceeded for tablespace
    Linux core 文件(二)
    Linux core 文件(一)
    完全卸载oracle11g步骤
    oracle11gr2 for windows 32-bit win7安装与卸载
    Oracle的几个概念:数据库名,全局数据库名,SID,实例,命名空间,schema
    cut 字符截取命令
  • 原文地址:https://www.cnblogs.com/qiangini/p/14907915.html
Copyright © 2011-2022 走看看