JDK版本jdk1.8.0_241
JDBC驱动要对应JDK版本
因此JDBC使用DmJdbcDriver18
DM7
在Linux系统上,IP:192.168.152.130,端口号5236
u/p:SYSDBA/SYSDBA
4个最基础参数
jdbc.driver=dm.jdbc.driver.DmDriver
jdbc.url=jdbc:dm://localhost:5236
jdbc.username=test
jdbc.password=Test12345
加载JDBC驱动
新建Java工程,包,类后添加DmJDBCDriver18驱动
达梦数据库的dmdbms文件夹下的jdbc文件自带JDBC驱动,因此只需选择DmJdbcDriver18的jar包
添加驱动所在位置
添加完后,
编写class
```java
package Connectiton;
import java.sql.*;
public class connectDM {
private static Connection conn=null; //定义连接对象
private static String url="jdbc:dm://192.168.152.130:5236";
private static String user="SYSDBA";
private static String passwd="SYSDBA";
public static void connect() throws SQLException{
try{
Class.forName("dm.jdbc.driver.DmDriver"); //加载
}catch (ClassNotFoundException e){
throw new SQLException("Connect to DM Server Error:"+e.getMessage());
}
try{
conn =DriverManager.getConnection(url,user,passwd); //连接到虚拟机上的DM7
System.out.println("connect success");
String sql="select * from \"GIN\".\"APP_USER\"";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) //输出查询结果中的ID,ORGAN列
{
System.out.print(rs.getString("ID")+" ");
System.out.println(rs.getString("ORGAN"));
}
rs.close();
stmt.close();
conn.close();
}catch (SQLException e){
throw new SQLException(e.getMessage());
}
}
public static void main(String[] args) throws SQLException {
connect();
}
}
输出结果显示