package lianjie;
import java.sql.Connection;
import java.sql.DriverManager;
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";
// 定义连接对象
Connection conn = null;
/* 加载 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();
} 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();
basicApp.disConnect();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
export JAVA_HOME=/usr/local/java/jdk1.6.0_38
export JRE_HOME=/usr/local/java/jdk1.6.0_38/jre
export DMDB_HOME=/opt/dmdbms
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$HIVE_HOME/lib:$DMDB_HOME/jdbc/Dm7JdbcDriver16.jar
export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$HIVE_HOME/bin:$JRE_HOME/bin:$PATH
配置classpath 我的classpath也配置指向了dm7driver包,jdk是1.6的,在安装目录bin下面disql是可以登录数据库的
为什么就连不上呢,还需要做什么?
6 个解决方案
#1
有异常信息不?
#2
没有,就输出
Loading JDBC Driver...
Load JDBC Driver Error1: dm7.jdbc.driver.DmDriver
Loading JDBC Driver...
Load JDBC Driver Error1: dm7.jdbc.driver.DmDriver
#3
刚代码格式没放好 再传一次
package lianjie;
import java.sql.Connection;
import java.sql.DriverManager;
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";
// 定义连接对象
Connection conn = null;
//* 加载 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();
} 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();
basicApp.disConnect();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
#4
问题已经解决
#5
楼主,咋解决的呀,在线等。。。。。。。
#6
怎么解决的啊
#1
有异常信息不?
#2
没有,就输出
Loading JDBC Driver...
Load JDBC Driver Error1: dm7.jdbc.driver.DmDriver
Loading JDBC Driver...
Load JDBC Driver Error1: dm7.jdbc.driver.DmDriver
#3
刚代码格式没放好 再传一次
package lianjie;
import java.sql.Connection;
import java.sql.DriverManager;
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";
// 定义连接对象
Connection conn = null;
//* 加载 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();
} 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();
basicApp.disConnect();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
#4
问题已经解决
#5
楼主,咋解决的呀,在线等。。。。。。。
#6
怎么解决的啊