Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
public class Connectionsmanager {Connection conn;
String user = "Dada";
String password = "Dandan"; /** * Acquisition of Oracle connection * @return * @throws Exception/public Connection Getoracleconn () throws Exception {String
url = "Jdbc:oracle:thin:@127.0.0.1:1521:dandan";
Class.forName ("Oracle.jdbc.driver.OracleDriver");
conn = drivermanager.getconnection (URL, user, password);
Return conn; /** * Get MySQL connection * @return * @throws Exception/public Connection Getmysqlconn () throws Exception {String
url = "Jdbc:mysql://127.0.0.1/dandan";
Class.forName ("Org.gjt.mm.mysql.Driver");
conn = drivermanager.getconnection (URL, user, password);
Return conn;
/** * Get SQL Server connection * @return * @throws Exception/public Connection Getsqlserverconn () throws Exception { String url = "Com.microsoft.jdbc.sqlserver.SQLServerdriver ";
Class.forName ("Com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = drivermanager.getconnection (URL, user, password);
Return conn; /** * Get ODBC connection * @return * @throws Exception/public Connection Getodbcconn () throws Exception {String u
RL = "Jdbc:odbc:ExcelODBC1";
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
conn = drivermanager.getconnection (URL, user, password);
Return conn;
It should be noted that when querying using ODBC, there are some differences with standard SQL//need to use "[]" to enclose the name of the table to be queried//Statement stmt=con.createstatement ();
ResultSet rs=stmt.executequery ("select * from [sheet1$]"); /** * Get access connection * @return * @throws Exception/public Connection Getaccessconn () throws Exception {Stri
ng url = "Jdbc:odbc:test";
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
conn = drivermanager.getconnection (URL, user, password);
Return conn; /** * Get SQL Server connection through ODBC * @return * @throws Exception/public Connection getSqlServerConn1 () throws Exception {String url = ' JDBC:ODBC:MYDB1 ';
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
conn = drivermanager.getconnection (URL, user, password);
Connection con =//Drivermanager.getconnection ("Jdbc:odbc:mydb1;database=pubs", "", "");
Return conn; /** * Access to connection via OCI * * * This way only to get a connection to Oracle * @return * @throws Exception * * Public Connection getconnbyoci () th
Rows Exception {class.forname ("oracle.jdbc.driver.OracleDriver");
Connection conn =//Drivermanager.getconnection ("Jdbc:oracle:oci: @dandan", "Root", "Dada"); Connection conn = DriverManager. getconnection (jdbc:oracle:oci:@ (description= (address=) host=127.0.0.1
L=TCP) (port=1521)) (Connect_data= (SID=ORA9)) "," Scott "," Tiger ");
Return conn;
}
}