zoukankan      html  css  js  c++  java
  • Mysql测试链接

    public class GetConnectionMysql {
    	public static Connection getConnection(){
    		String driver="com.mysql.jdbc.Driver";   //获取mysql数据库的驱动类
    		String url="jdbc:mysql://133.96.46.100:3306/test"; //连接数据库(test是数据库名)
    		String name="root";//连接mysql的用户名
    		String pwd="root";//连接mysql的密码
    		Connection conn= null;
    		try {
    			Class.forName(driver);
    		} catch (ClassNotFoundException e1) {
    			System.out.println("驱动加载失败");
    			e1.printStackTrace();
    		}
    		try{
    			conn=DriverManager.getConnection(url,name,pwd);//获取连接对象
    			System.out.println("成功连接数据库!");
    			return conn;
    		}catch(SQLException e){
    			e.printStackTrace();
    			return null;
    		}finally {
    			if(conn!=null){
    				try {
    					conn.close();
    				} catch (SQLException e) {
    					e.printStackTrace();
    				}
    			}
    		}
    	}
    	
    	public static void closeAll(Connection conn,PreparedStatement ps,ResultSet rs){
    		try{
    			if(rs!=null){
    				rs.close();
    			}
    		}catch(SQLException e){
    			e.printStackTrace();
    		}
    		try{
    			if(ps!=null){
    				ps.close();
    			}
    		}catch(SQLException e){
    			e.printStackTrace();
    		}
    		try{
    			if(conn!=null){
    				conn.close();
    			}
    		}catch(SQLException e){
    			e.printStackTrace();	
    		}
    	}
    	
    	public static void main(String[] args) throws SQLException
    	{
    		
    		Connection cc=GetConnectionMysql.getConnection();
    	}
    }
    

      

  • 相关阅读:
    优化Android Studio/Gradle构建
    Android sdk 搭建
    map排序
    单例
    一些rtsp实现的开源代码
    MySQL性能优化/调优:默认配置的修改
    mysql 优化 实现命中率100%
    mysql性能优化-慢查询分析、优化索引和配置
    findbugs规则
    网络编程及并发编程总结
  • 原文地址:https://www.cnblogs.com/zt528/p/5291890.html
Copyright © 2011-2022 走看看