此次由于学习上面的事情,接触到了达梦数据库,这是第一次用,去年有个关于隐通道的课程设计,其实就已经差很少算了解了点点,相对与国外主流数据库,Dm7有个很明显的特色,那就是它的安全级别,国外数据卖给中国的最高等级是C2级,也就是说,根本没有达到B级,这就意味这更本就没有强制访问概念,而达梦能支持到B级,也就支持强制访问java
下面介绍在linux下面jdbc链接达梦数据库。linux
最新DM7有linux版本,在官网能够下载,也有安装方法。sql
java代码在安装目录desktop里面的manual里面有,以下:数据库
package lianjie; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import javax.imageio.ImageIO; public class BasicApp { // 定义 DM JDBC 驱动串 String jdbcString = "dm.jdbc.driver.DmDriver"; // 定义 DM URL 链接串 String urlString = "jdbc:dm://localhost:5236/hive"; // 定义链接用户名 String userName = "SYSDBA"; // 定义链接用户口令 String password = "SYSDBA"; static //定义sql语句 //String sqlString ="create table yujin3(a int,b int,c int);"; String sqlString1="insert into yujin3 values(123,14,1234);"; // 定义链接对象 static Connection conn = null; //private static String sqlString1; /* 加载 JDBC 驱动程序 * @throws SQLException 异常 */ public void loadJdbcDriver() throws SQLException { try { System.out.println("Loading JDBC Driver..."); // 加载 JDBC 驱动程序 //DriverManager.registerDriver(new dm.jdbc.driver.DmDriver()); Class.forName(jdbcString); } catch (ClassNotFoundException e) { throw new SQLException("Load JDBC Driver Error1: " + e.getMessage()); } catch (Exception ex) { throw new SQLException("Load JDBC Driver Error : " + ex.getMessage()); } } public void connect() throws SQLException { try { System.out.println("Connecting to DM Server..."); // 链接 DM 数据库 conn = DriverManager.getConnection(urlString, userName, password); } catch (SQLException e) { throw new SQLException("Connect to DM Server Error : " + e.getMessage()); } } /* 关闭链接 * @throws SQLException 异常 */ public void disConnect() throws SQLException { try { // 关闭链接 conn.close(); System.out.println("close"); } catch (SQLException e) { throw new SQLException("close connection error : " + e.getMessage()); } } public static void main(String args[]) { try { BasicApp basicApp = new BasicApp(); // 加载驱动程序 basicApp.loadJdbcDriver(); basicApp.connect(); PreparedStatement pstmt1 = conn.prepareStatement(sqlString1); //pstmt1.setInt(1,11); //pstmt1.setInt(2, 12); //pstmt1.setInt(3, 123); pstmt1.execute(); // 关闭语句 pstmt1.close(); System.out.println("OK!"); basicApp.disConnect(); } catch (SQLException e) { System.out.println(e.getMessage()); } } }
注意在链接以前要保证Dmserver已经启动。安全
至于网上说的要配置classpath,我刚开始值配置了classpath并无导入jdbc驱动包,不行,而后导入就可一了,本身以为在导入包以后应该不用配置了
学习