The examples in this article describe the Java-derived classes for MySQL and Oracle links. Share to everyone for your reference. as follows:
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.SQLException; public class Connectdb {private static final string MYSQL = "jdbc:mysql://"; private static final String ORACLE = "Jdbc:o
racle:thin:@ "; Private Connectdb () {} public static Connection getinstance (string DBType, String url) throws Nosuchdbexception, Sqlexcep tion {if ("MySQL". Equalsignorecase (DBType)) return getmysqlconn (URL); if ("Oracle" Equalsignorecase (DBType)) return
Getoracleconn (URL);
return null; public static void Closeconn (Connection conn) {if (conn!= null) {try {conn.close ();} catch (SQLException e) {E.pri
Ntstacktrace (); }} private static Connection getmysqlconn (String url) throws SQLException {Connection = null; try {conn
("Com.mysql.jdbc.Driver"); catch (ClassNotFoundException e) {e.printstacktrace ();} conn = drivermanager.getconnection (MYSQL + URL, "root", "root"
);
Return conn; private static Connection getoracleconn (String url) throws SQLException {
Connection conn = null; try {class.forname ("Oracle.jdbc.driver.OracleDriver");} catch (ClassNotFoundException e) {e.printstacktrace ();} conn
= drivermanager.getconnection (ORACLE + URL, "Scott", "Tiger");
Return conn;
}
}
I hope this article will help you with your Java programming.