当前位置:Gxlcms > 
数据库问题 > 
MySQL、Oracle、Sql Server数据库JDBC的连接方式
                     
                    
                        MySQL、Oracle、Sql Server数据库JDBC的连接方式
                        
                            时间:2021-07-01 10:21:17
                            帮助过:2人阅读
							                        
                     
                    
                    
                    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);       //连接数据库
 
MySQL、Oracle、Sql Server数据库JDBC的连接方式
标签: