1、新建一个java project
(maven项目前几次在导jar时总是出错,下次再试试。)
2、打开file里的project structure,打开libraries,点击+号,选择java,在idea中添加外部jar包——jar包选择DmJdbcDriver18.jar;
如果需要原生jdbc,导入这一个jar包即可;
(我以前一直以为还要导入一个jdbc jar包,后来发现不用,jdbc是一种接口规范,已经存在我们安装的jdk中了,我们只要导入了jdk,自然也就导入了jdbc接口规范,DmJdbcDriver18.jar就是实现这种接口规范的类。)(经查找,JDBC接口规范定义在java.sql包中,另外,在javax.sql中也有相关的API。)
3、正常原生jdbc使用
packagecom.ssy.dao;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.SQLException;
public classTest {
public int insert() throwsClassNotFoundException, SQLException {
//1.regedit driver
Class.forName("dm.jdbc.driver.DmDriver");
//2.get connection
Connection connection = DriverManager.getConnection("jdbc:dm://localhost:5236","SYSDBA","SYSDBA");
//3.excute sqlstring
String sqlString = "insert into SYSDBA.TB(id, book) values(131,'dsaf');";
java.sql.Statement statement =connection.createStatement();
int exSta =statement.executeUpdate(sqlString);
if (statement != null)
{
//4、release
statement.close();
}
returnexSta;
}
public static void main(String[] args) throwsSQLException, ClassNotFoundException {
Test t = newTest();
t.insert();
}
}