Mysql, sqlserver, DB2, Oracle, hsql database for the database connection method

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Test {
	/**
	 * Access to the database connection method
	 * @Param driverName driver
	 * @param url url
	 * @Param userName user name
	 * @Param password password
	 * @return
	 */
	public static Connection getConn(String driverName, String url, String userName, String password) {
			Connection connection = null;
			try {
				Class.forName(driverName);
				connection = DriverManager.getConnection(url, userName, password);
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		return connection;
	}

	public static void main(String[] args) {
		
		//mysql
		Connection conn = getConn("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/The database name, user name]" " " ", password");
//		//sqlserver
//		Connection conn = getConn("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://[remote IP]: [port]; Database Name=[database name, username]" " " ", password");
//              //hsql
//		Connection conn = getConn("org.hsqldb.jdbcDriver", "jdbc:hsqldb:hsql://[remote IP]: [port / database name, user name]" " " ", password");
//		//oracle
//		Connection conn = getConn("oracle.jdbc.OracleDriver", "jdbc:oracle:thin:@[remote IP]: [port]: [database name, user name]" " " ", password");
//		//db2
//		Connection conn = getConn("com.ibm.db2.jcc.DB2Driver", "jdbc:db2://[remote IP]: [port / database name, user name]" " " ", password");
		
		System.out.println(conn);   //Print database driver

	}
}

SQL paging query:

//oracle

select * from (select rownum rm, * from tableName where rownum<(startRow+rowNum)) where rm>=startRow;

//mysql

select * from tableName limit startRow , rowNum ;

//sqlserver

select top (startRow + rowNmu) from tableName ;

//db2

select * from tableName limit startRow , rowNum ;

//hsql

select limit startRow rowNum * from (select * from tableName) ;



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Gladys at December 06, 2013 - 12:48 PM