SQL Server, Oracle, and MySQL connections, except the address and the driver package, the others are the same.
1Public String urlstring= "Jdbc:sqlserver://localhost:1433;databasename=crebas;";2//"Jdbc:mysql://Localhost:3306/crebas?autoreconnect=true&useunicode=true&characterencoding=utf8 "3//"Jdbc:oracle:thin: @localhost: 1521:orcl"4Public String namestring= "SA";5Public String password= "123";6PublicvoidTest ()7{8 String Driver = "Com.microsoft.sqlserver.jdbc.SQLServerDriver";9//"Com.mysql.jdbc.Driver"10//"Oracle.jdbc.driver.OracleDriver"11Try12{13Class.forName (driver);Connection conn =Drivermanager.getconnection (urlstring, namestring, password);PreparedStatement pstmt = conn.preparestatement ("SELECT * from T_admin");16 ResultSet rs = Pstmt.executequery (); 17 Rs.next (); catch (Exception e) {23 24 }25}
The most basic connection way, long time ago tidy up, forget about.