java通过oshi获取系统和硬件信息 / Oshi get system and hardware information

OSHI 是用java写的系统监控工具接口,提供主要的监控指标信息,具体接口作用如下: maven 依赖引入 1 2 3 4 5 6 <dependency> <groupId>com.github.oshi</groupId> <artifactId>oshi-core</artifactId> <version>4.0.0</version> </dependency> API 操作 1 2 3 4 5 6 7 8 9 // 初始化系统信息对象 SystemInfo systemInfo = new SystemInfo(); // 获取硬件信息 HardwareAbstractionLayer hardware = systemInfo.getHardware(); // 获取操作系统进程相关信息 OperatingSystem operatingSystem = systemInfo.getOperatingSystem(); 操作BIOS系统信息 获取 BIOS 系统信息 1 2 3 4 5 6 7 8 ComputerSystem computerSystem = hardware.getComputerSystem(); Firmware firmware = computerSystem.getFirmware(); String name = firmware.getName(); String description = firmware.getDescription(); String firmwareManufacturer = firmware.getManufacturer(); String releaseDate = firmware.getReleaseDate(); String firmwareVersion = firmware.getVersion(); 传感器信息 风扇/温度信息 ...

September 27, 2019 · 2 min · 338 words · atovk

JDBC链接各种数据库的例子 / Java jdbc example holder

java语言下 jdbc 各种数据库的链接方式 mysql/mariadb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 private static Connection getConn() { String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/samp_db"; String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } oracle (1)Oracle JDBC Thin using a ServiceName: 1 2 #jdbc:oracle:thin:@//<host>:<port>/<service_name> #Example: jdbc:oracle:thin:@//192.168.2.1:1521/XE (2)Oracle JDBC Thin using an SID: 1 2 #jdbc:oracle:thin:@<host>:<port>:<SID> #Example: jdbc:oracle:thin:@192.168.2.1:1521:X01A (3)Oracle JDBC Thin using a TNSName: 1 2 #jdbc:oracle:thin:@<TNSName> #Example: jdbc:oracle:thin:@GL 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // 获得连接对象 private static Connection getConn() { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@//127.0.0.1:1521/orcl"; String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } sqlserver 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // sqlserver2012 private static Connection getConn() { String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; String url = "jdbc:sqlserver://localhost:1433;DatabaseName=student"; String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } db2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 private static Connection getConn() { String driver = "com.ibm.db2.jcc.DB2Driver"; String url = "jdbc:db2://10.27.70.33:60000/dbtest:currentSchema=db2inst1"; String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } PostgreSQL 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 private static Connection getConn() { String driver = "org.postgresql.Driver"; String url = "jdbc:postgresql://127.0.0.1:5432/test"; String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } greenplum 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 private static Connection getConn() { String driver = "com.pivotal.jdbc.GreenplumDriver"; String url = "jdbc:pivotal:greenplum://10.10.10.10:5432;DatabaseName=mfg"; String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } hana 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 private static Connection getConn() { String driver = "com.sap.db.jdbc.Driver"; String url = "jdbc:sap://172.23.1.123:39015"; String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } hive 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 private static Connection getConn() { /** hiveserver org.apache.Hadoop.hive.jdbc.HiveDriver jdbc:hive://localhost:10000/default hiveserver2 org.apache.Hive.jdbc.HiveDriver jdbc:hive2://localhos:10000/default */ String driver = "org.apache.hive.jdbc.HiveDriver"; String url = "jdbc:hive2://localhos:10000/default"; String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } sybase 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 private static Connection getConn() { String Driver = "com.sybase.jdbc3.jdbc.SybDriver"; //数据库驱动 String url = "jdbc:sybase:Tds:192.168.2.103:5000/SXABC"; // 连接的数据库是SXABC String username = "root"; String password = ""; Connection conn = null; try { Class.forName(driver); //classLoader,加载对应驱动 conn = (Connection) DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; }

September 13, 2019 · 4 min · 682 words · atovk