连接各种数据库
1.连接oracle
String url = "jdbc:oracle:thin:@localhost:1521:ORCL"; String user = "scott"; String password = "tiger"; //1.加载驱动,反射要根据完整的路径查找 Class.forName("oracle.jdbc.driver.OracleDriver"); //2.建立连接 Connection con = DriverManager.getConnection(url,user,password);
2.连接mySql
Class.forName("com.mysql.jdbc.Driver");     //加载MYSQL JDBC驱动程序     
Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root",  "050818" + "");  
// 连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码  
3 . 执行数据库操作
sta.executeQuery(sql); //执行查询 sta.executeUpdate(sql);//执行修改 sta.executeBatch();//批量插入
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号