java SE连接mysql

java SE连接mysql

package com.java_mysql_test_se;
import java.sql.*;


public class main {
    Connection con;
    public Connection getConnection(){
        try{
            Class.forName("com.mysql.jdbc.Driver");//数据库驱动加载
            System.out.println("数据库驱动加载成功");
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
    
            String uri="jdbc:mysql://192.168.10.100:3306/txw_oqa_db";
            String user="root";
            String password="87958868";
            try {
                System.out.println("这里被执行了!");
                con= (Connection) DriverManager.getConnection(uri,user,password);
                System.out.println("连接成功!");

            }catch(Exception e)
            {
                System.out.println("连接失败!");
            }
        
        
        return con;
    }
    public static void main(String[] args){
        main c=new main();
        c.getConnection();
    }
 
}

 

posted @ 2022-06-13 20:14  txwtech  阅读(42)  评论(3编辑  收藏  举报