yzwj2004 发表于 2017-7-13 22:03:02

MySQL、Oracle、Sql Server数据库JDBC的连接方式

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);       //连接数据库
页: [1]
查看完整版本: MySQL、Oracle、Sql Server数据库JDBC的连接方式