linux下面 达梦数据库的JDBC连接

这次因为学习上面的事情,接触到了达梦数据库,这是第一次用,去年有个关于隐通道的课程设计,其实就已经差不多算了解了点点,相对与国外主流数据库,Dm7有个很明显的特点,那就是它的安全级别,国外数据卖给中国的最高等级是C2级,也就是说,根本没有达到B级,这就意味这更本就没有强制访问概念,而达梦能支持到B级,也就支持强制访问

下面介绍在linux下面jdbc连接达梦数据库。

最新DM7有linux版本,在官网可以下载,也有安装方法。

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());}}}

在建号的java工程中右击buildpath然后ADD 加入jdbc驱动,这里注意,DmDriver16支持jdk1.6的,相应的15,14支持1.5,1.4,然后就可一操作了,

注意在连接之前要保证Dmserver已经启动。

至于网上说的要配置classpath,我刚开始值配置了classpath并没有导入jdbc驱动包,不行,然后导入就可一了,自己觉得在导入包之后应该不用配置了

带着感恩的心启程,学会爱,爱父母,爱自己,爱朋友,爱他人。

linux下面  达梦数据库的JDBC连接

相关文章:

你感兴趣的文章:

标签云: