Java学习中MySQL、Oracle、Sql Server数据库JDBC的连接方式

转载:https://www.cnblogs.com/huanght/p/5841193.html

MySQL、Oracle、Sql Server数据库JDBC的连接方式
MySQL:
                 先添加MySQL的jar包
                 String url=”jdbc:mysql://localhost:3306/数据库名”;       //数据库地址
                 String name=”root”;       //数据库用户名
                 String password=”123456”;       //数据库用户密码
                 Class.forName(“com.mysql.jdbc.Driver”) ;      //加载MySQL驱动
                 Connection conn = DriverManager.getConnection(url,name,password);       //连接数据库
 
Oracle:
                添加Oracle的jar包
                String url=”jdbc:oracle:thin:@localhost:1521:数据库名” ;      //数据库地址
                String name=”数据库用户名”;       //数据库用户名
                String password=”数据库用户密码”;       //数据库用户密码
                Class.forName(“oracle.jdbc.driver.OracleDriver”);       //加载oracle驱动
                Connection conn = DriverManager.getConnection(url,name,password);       //连接数据库
 
Sql Server:
                     添加Sql Server的jar包
                     String url=”jdbc:sqlserver://localhost:1433;DatabaseName=数据库名”;       //数据库地址
                     Sring name=”数据库用户名”;       //数据库用户名
                     String password=”数据库用户密码”;       //数据库用户密码
                     Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);       //加载Sql Server驱动
                     Connection conn = DriverManager.getConnection(url,name,password);       //连接数据库
 

猜你喜欢

转载自blog.csdn.net/zz13995900221/article/details/80210479