简单测试数据库连接

package com.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class JustExcuteSimpleToTest {
    public static String DataBaseURL = "jdbc:mysql://localhost:3306/gaoxiangyu";
    public static String username = "root";
    public static String password  = "root";
    public static String DriverPath = "com.jdbc.mysql.Driver";

    public static void main(String[] args) throws SQLException {
        // TODO Auto-generated method stub
        try{
            Connection conn = null;
            conn = DriverManager.getConnection(DataBaseURL, username, password);//加载驱动,并建立连接
            Statement st = conn.createStatement();//
            System.out.println(st.execute("select * from gaoxiangyu.userinfo"));
            st.close();
            conn.close();
        }catch(Exception e){
            e.printStackTrace();
        }

    }

}

 

posted on 2017-07-18 21:49  笑傲江湖未平生  阅读(151)  评论(0编辑  收藏  举报