通过JDBC驱动连接Hive操作失败

hive版本:1.2.1

Hive.java程序片段:

Class.forName("org.apache.hive.jdbc.HiveDriver");

在centos上,通过javac -classpath对Hive.java 编译。相应的jar:hive-jdbc,hive-exec,hive-metastore 放在-classpath后面了。
编译成功;
通过jar cvf 打包成功为hive.jar.
然后通过 hadoop jar hive.jar com.aturbo.hadoop.Hive执行的时候,以后报下面的错:
Exception in thread "main" java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at com.aturbo.hadoop.Hive.main(Hive.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:160)

不知道什么原因,求大神帮忙!

0

3个回答

已解决,导入更多的包,采用脚本的方式

0
chernzy
chernzy 采用脚本方式?什么意思
10 个月之前 回复

iu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

0

你好 我的错误和你的类似 能说一下你怎么解决的吗?
java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.beicai.hiveProject.HiveJDBCConection.main(HiveJDBCConection.java:18)

我把该到的jar包都导进去了
0
MyOwnCCS
MyOwnCCS 同问,现在我的也是,求指导,谢谢
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
通过JDBC连接Hive
使用JDBC去操作hive可能是程序员们比较喜欢的一种方式,今天来总结一下使用java api来对hive进行增删查改,这里我主要演示对hive表中数据的操作,不创建表已经改变表原有的结构。本文基于hive已经能正常使用的情况。 首先hive必须以服务方式启动,平台默认启动时hive server2 模式。hiveserver2是比hiveserver更高级的服务模式,提供了hiveserver...
通过JDBC连接hive
hive是大数据技术簇中进行数据仓库应用的基础组件,是其它类似数据仓库应用的对比基准。基础的数据操作我们可以通过脚本方式以hive-client进行处理。若需要开发应用程序,则需要使用hive的jdbc驱动进行连接。本文以hive wiki上示例为基础,详细讲解了如何使用jdbc连接hive数据库。hive wiki原文地址: https://cwiki.ap...
java通过JDBC驱动连接操作hive实例
Hive提供了jdbc驱动,使得我们可以用java代码来连接Hive并进行一些类关系型数据库的sql语句查询等操作。首先,我们必须将Hive的服务,也就是HiveServe打开。在Hive 0.11.0版本前,只有HiveServer服务可用,但是HiveServer本身存在很多问题(比如:安全性、并发性等);针对这些问题,Hive-0.11.0版本后提供了一个全新的服务:HiveServer2,
hive的jdbc连接驱动包
hive的jdbc连接,亲身试验可以使用,但有时还需要hive其他环境
Java通过jdbc连接HIVE
一、连接 public static void main(String[] args) throws SQLException { try { Class.forName("org.apache.hive.jdbc.HiveDriver"); } catch (ClassNotFoundException e) { // TODO Auto-generated cat...
Java通过JDBC连接Hive
本文是通过JDBC连接HiveServer2。 首先需要开启Hive远程服务接口。具体操作请百度。 然后是找到各种jar包。 我之前多次出错的原因就在于jar包不对,选用的jar包只能连接HiveServer。 我整理的jar下载网址为:http://download.csdn.net/detail/q2011zhuce/9467164 Java连接Hive示例代码import
通过JDBC来连接Hive
在大数据分析中,Hive作为历史数据挖掘分析工具,用到的很多,我们可以通过Hive的命令行来很方便地操作Hive中的数据,但是很多时候我们都需要将Hive的操作融入到编程环境中去,而Hive提供了JDBC接口,因而我们可以很方便地通过JDBC来操作Hive。下面就记录一下通过JDBC来连接Hive的过程:         第一步:启动集群中的Mysql服务(在安装mysql的那个节点上)
Java通过JDBC操作Hive
1. hadoop的配置文件core-site.xml中 fs.defaultFS hdfs://hadoop1:9000 hadoop.tmp.dir /usr/local/softinstall/hadoop/workspace/hdfs/temp
Hive客户端JDBC连接操作
创建maven工程pom.xml------------------------------<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/P...
jdbc连接hive数据库的驱动jar包
jdbc连接hive数据库的jar包.整理可用合集.
hive建立JDBC连接需要的驱动jar包
这是用于与HIVE建立JDBC连接的驱动jar包,经过测试,是可以使用的。
hive-jdbc hive jdbc驱动
hive-jdbc
jdbc 通过impala 连接hive库
一直在网上找不到impalajdbc的pom依赖,项目是maven的,所以整理了所用的pom
通过JDBC连接Hive以及常见异常处理方式
环境 1.hadoop-2.7.3集群 2.hive-1.2.2 测试代码 1.JDBCUtils.java package demo.utils; import java.sql.*; public class JDBCUtils { private static String driver = "org.apache.hive.jdbc.HiveDrive
eclipse使用jdbc连接hive操作
 操作版本:      jdk1.8   hadoop-2.7.4   hive-2.3.3 1,我们创建的maven项目在pom文件下添加依赖信息如下 <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</...
jdbc操作hive出现连接拒绝
1 出现的问题:                jdbc在操作hive时,出现了拒绝连接   2 出现问题的原因:      这是因为没有在服务端开启HiveServer2服务   3 解决方法:            到hive的bin目录下输入 ./hive --service hiveserver2  开启服务,这样就可以连接成功了              ...
使用JDBC连接和操作hive(hiveserver2)
第一步:创建项目 并导入hive相关jar包第二步:编写代码如下:import java.sql.Statement;import java.sql.DriverManager;import org.apache.tools.ant.taskdefs.Echo;public class TestHive2 { private static String driverName = "org.apa...
jdbc连接hive
本代码中demo讲解了如果使用jdbc连接cdh搭建的hive环境信息
jdbc连接hive的问题
利用hive jdbc连接hive出现如下问题:   org.apache.hive.jdbc.HiveDriverorg.apache.hive.jdbc.HiveDriverhive_driver: org.apache.hive.jdbc.HiveDriverhive_url:jdbc:hive2://10.174.242.28:10000/defaultget connection
jdbc连接hive的jar包
亲测有用,在ambari2.5.2下安装的hadoop版本,后面的版本应该都没问题
jdbc连接hive工具类
使用jdbc连接hive 里面提供了很多封装方法 .....................................................................
Jdbc连接Hive数据库
Jdbc连接Hive数据库通常会遇到:     报错:jdbc:hive2://master0.example.com:10000: Java.NET.ConnectException: Connection refused: connect 首先来看下maven的配置文件: 接着是hive-site.xml文件:    
jdbc 连接impala或者jdbc连接hive
jdbc 连接impala或者jdbc连接hive所需的jar包。
Hive JDBC连接
hive2.3.2 JDBC连接 ,sql developer可用。选择第三方jdbc,加入,就可以显示hive连接。用的cloudra的jdbc用于连接操作数据库,java开发请使用maven获取开源组件。
JDBC连接Hive实例
JDBC连接hive,用JD连接hive。
hive jdbc连接Demo
jdbc连接hive的小示例程序,使用方法: 1、在Hadoop服务器上启动远程服务接口,命令: nohup hive --service hiveserver 10000 & (指定端口启动) 2、将test主程序里的IP改为自己用的Hadoop服务器ip,即可使用。
使用JDBC操作Hive
首先启动 Hive 的远程服务:hiveserver2 & 所需 jar 包的 pom 文件如下: <dependencies> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> &
HIVE JDBC连接详解
packageorg.conan.myhadoop.mr; importjava.sql.Connection; importjava.sql.DriverManager; importjava.sql.ResultSet; importjava.sql.SQLException; importjava.sql.Statement; p...
HIVE JDBC方法连接
输入 hiveserver2 打开hive server2 在之前的学习和实践Hive中,使用的都是CLI或者hive –e的方式,该方式仅允许使用HiveQL执行查询、更新等操作,并且该方式比较笨拙单一。幸好Hive提供了轻客户端的实现,通过HiveServer或者HiveServer2,客户端可以在不启动CLI的情况下对Hive中的数据进行操作,两者都允许远程客户端使用多种编程语言如Ja...
hive连接jdbc的jar包
数据库连接jar包,可以用来连接客户端,dbv等,sql developer客户端等
Hive之JDBC操作
package com.uplooking.bigdata.sql; import com.uplooking.bigdata.domain.Student; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.sql.*; /**  * Java版本,最后对结
jdbc驱动加载失败
除了需要在referenced libraries中加入mysql connector的jar包以外,还需要在web-info的library中加入connector jar包,然后右键build path-->add。。
Java 通过jdbc 驱动形式连接Oracle数据库
本人小白,初学Java jdbc连接  害怕自己忘记相关知识,特此记录一下: 首先,创建一个普通的Java工程,然后将Oracle 目录下的jdbc.jar包拖进工程根目录下,如图所示 然后需要将将此jar包build进工程中: (拖进去之后可以右键add build) 准备工作就算完成了. 开始写 心中要明确jdbc是如何连接数据库的 大约就是:注册驱动  Class....
hive的访问:通过JDBC远程连接hive数据仓库
hive的访问:终端访问  远程访问 终端访问:安装hive,利用shell脚本访问 不可并发访问 远程访问:通过JDBC连接数据仓库 支持并发访问 启动hiveserver2服务:查看该命令可知hiveserver2,等价于hive --service hiveserver2 & [xiaoqiu@s150 /soft/hive/bin]$ cat hiveserver2 #...
JDBC连接Mysql数据库失败
求助,不知道哪里错了rnrn[b],运行错误提示[/b]rn[code=java]com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:423)rn at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)rn at com.mysql.jdbc.Util.getInstance(Util.java:408)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)rn at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2163)rn at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2088)rn at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:806)rn at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:423)rn at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)rn at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)rn at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)rn at java.sql.DriverManager.getConnection(DriverManager.java:664)rn at java.sql.DriverManager.getConnection(DriverManager.java:247)rn at HelloJDBC.helloworld(HelloJDBC.java:22)rn at HelloJDBC.main(HelloJDBC.java:52)rnCaused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failurernrnThe last packet successfully received from the server was 30 milliseconds ago. The last packet sent successfully to the server was 29 milliseconds ago.rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:423)rn at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)rn at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)rn at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:164)rn at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4898)rn at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1659)rn at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)rn at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)rn at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2104)rn ... 14 morernCaused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetrn at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)rn at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)rn at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)rn at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)rn at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509)rn at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)rn at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)rn at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)rn at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)rn at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)rn at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)rn at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)rn at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:149)rn ... 19 morernCaused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetrn at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)rn at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)rn at sun.security.validator.Validator.validate(Validator.java:260)rn at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)rn at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)rn at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)rn at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)rn ... 27 morernCaused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetrn at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)rn at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)rn at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)rn at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)rn ... 33 morern[/code]rnrn[b]这是源码[/b]rn[code=objc]import java.sql.*;rnrnpublic class HelloJDBC rnrn static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";rn static final String DB_URL = "jdbc:mysql://localhost:3306/zyh?useSSL=true&&autoReconnect=true";rn rn static final String USER = "zhangyh";rn static final String PASSWORD = "123456";rn rn public static void helloworld() throws ClassNotFoundException rn Connection conn = null;rn Statement stmt = null;rn ResultSet rs = null;rn rn //1.装载驱动程序rn Class.forName(JDBC_DRIVER);rn rn //2.建立数据库连接rn try rn rn DriverManager.getConnection(DB_URL, USER, PASSWORD);rn //3.执行SQL语句rn System.out.println("DSD");rn stmt = conn.createStatement();rn rs = stmt.executeQuery("select * name from zyh");rn System.out.println("dd");rn //4.获取执行结果rn while(rs.next())rn System.out.println("Hello" + rs.getString("sex"));;rn rn rn rn catch (SQLException e) rn // TODO: handle exceptionrn e.printStackTrace();rn finallyrn try rn if(conn != null)rn conn.close();rn if(stmt != null)rn stmt.close();rn if(rs !=null)rn rs.close();rn catch (Exception e2) rn e2.printStackTrace();rn rn rn rnrn public static void main(String[] arg) throws ClassNotFoundExceptionrn helloworld();rn rnrn[/code]rn这是数据库rn[code=sql]mysql> desc zyhrn -> ;rn+-----------+-------------+------+-----+---------+-------+rn| Field | Type | Null | Key | Default | Extra |rn+-----------+-------------+------+-----+---------+-------+rn| name | varchar(20) | YES | | NULL | |rn| sex | char(1) | YES | | NULL | |rn| birth | date | YES | | NULL | |rn| birthaddr | varchar(20) | YES | | NULL | |rn+-----------+-------------+------+-----+---------+-------+rn4 rows in set (0.00 sec)rnrnmysql> select * from zyh;rn+---------+------+------------+-----------+rn| name | sex | birth | birthaddr |rn+---------+------+------------+-----------+rn| zhangyh | M | 1992-12-12 | TZ |rn| syh | W | 1994-12-12 | SD |rn| syh | W | 1994-12-12 | SD |rn| ss | W | 1992-02-01 | SH |rn+---------+------+------------+-----------+rn4 rows in set (0.00 sec)rn[/code]rnrn[b]Server log[/b]rnTimestamp, Thread, Type, Detailsrn2017-02-08 18:34:18.467414, 78, Note, Access denied for user 'zhangyh'@'localhost' (using password: YES)rn2017-02-08 18:53:26.186115, 116, Note, Access denied for user 'zhangyh'@'localhost' (using password: YES)rn2017-02-08 18:53:29.562004, 117, Note, Access denied for user 'zhangyh'@'localhost' (using password: YES)rn2017-02-08 18:53:36.186621, 118, Note, Access denied for user 'zhangyh'@'localhost' (using password: YES)rn2017-02-08 18:53:39.352717, 119, Note, Access denied for user 'zhangyh'@'localhost' (using password: NO)
jdbc连接SQLServer 失败 !
异常如下:rn[code=Java]rn数据库连接失败rncom.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connectrnat com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)rnat com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)rnat com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)rnat com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)rnat com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)rnat java.sql.DriverManager.getConnection(DriverManager.java:582)rnat java.sql.DriverManager.getConnection(DriverManager.java:185)rnat com.university.TestJDBC.main(TestJDBC.java:27)rn[/code]rnrn望早日结贴!
JDBC连接sqlserver失败???
我通过cmd的telnet命令连接sqlserver的1433端口成功了,但是通过个DriverManager.getConnection()方法却连接失败??求大神帮助:代码:rn[code=java]rnpublic static void main(String[] args) rn String JDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";rn //SQL数据库引擎rn String connectDB="jdbc:sqlserver://.\\SQLEXPRESS:1433;DatabaseName=mysql";rn //数据源 rn try rn //加载数据库引擎,返回给定字符串名的类rn Class.forName(JDriver);rn catch(ClassNotFoundException e)rn rn //e.printStackTrace();rn System.out.println("加载数据库引擎失败");rn System.exit(0);rn rn System.out.println("数据库驱动成功");rn rn try rn String user="sa"; rn //这里只要注意用户名密码不要写错即可rn String password="12345";rn Connection con=DriverManager.getConnection(connectDB,user,password);rn //连接数据库对象rn System.out.println("连接数据库成功");rn Statement stmt=con.createStatement();rn //创建SQL命令对象rn rn //创建表rn System.out.println("开始创建表");rn //创建表SQL语句rn String query= "create table TABLE1(ID NCHAR(2),NAME NCHAR(10))";rn stmt.executeUpdate(query);//执行SQL命令对象rn System.out.println("表创建成功");rn rn //输入数据rn System.out.println("开始插入数据");rn String a1="INSERT INTO TABLE1 VALUES('1','旭哥')";rn //插入数据SQL语句rn String a2="INSERT INTO TABLE1 VALUES('2','伟哥')";rn String a3="INSERT INTO TABLE1 VALUES('3','张哥')";rn stmt.executeUpdate(a1);//执行SQL命令对象rn stmt.executeUpdate(a2); rn stmt.executeUpdate(a3);rn System.out.println("插入数据成功");rn rn //读取数据rn System.out.println("开始读取数据");rn ResultSet rs=stmt.executeQuery("SELECT * FROM TABLE1");//返回SQL语句查询结果集(集合)rn //循环输出每一条记录rn while(rs.next())rn //输出每个字段rn System.out.println(rs.getString("ID")+"\t"+rs.getString("NAME"));rn rn System.out.println("读取完毕");rn rn //关闭连接rn stmt.close();//关闭命令对象连接rn con.close();//关闭数据库连接rn catch(SQLException e)rn e.printStackTrace();rn System.out.print(e.getErrorCode());rn //System.out.println("数据库连接错误");rn System.exit(0);rn rn [/code]rnrn执行后控制台输出:rn数据库驱动成功rncom.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 . 的 TCP/IP 连接失败。错误:“null。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。rn0 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)rn at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1033)rn at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)rn at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)rn at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)rnrn
jdbc连接oracle数据库失败
各位大神,这个问题卡好久了,数据库一直连不上,不多说,直接上代码:rnjdbc.properties文件:rn[code=java]rnjdbc.driverClassName=oracle.jdbc.driver.OracleDriverrnjdbc.url=jdbc:oracle:thin:@192.168.1.106:1521:orclrnjdbc.username=rootrnjdbc.password=rootrnjdbc.maxActive=50rn[/code]rntnsnames.ora文件:rn[code=java]rnORACLR_CONNECTION_DATA =rn (DESCRIPTION =rn (ADDRESS_LIST =rn (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))rn )rn (CONNECT_DATA =rn (SID = CLRExtProc)rn (PRESENTATION = RO)rn )rn )rnrnORCL =rn (DESCRIPTION =rn (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.106)(PORT = 1521))rn (CONNECT_DATA =rn (SERVER = DEDICATED)rn (SERVICE_NAME = orcl.254.209.161)rn )rn )rn[/code]rnlistener.ora文件:rn[code=java]rnSID_LIST_LISTENER =rn (SID_LIST =rn (SID_DESC =rn (SID_NAME = CLRExtProc)rn (ORACLE_HOME = D:\install\Oracle\product\11.2.0\dbhome_1)rn (PROGRAM = extproc)rn (ENVS = "EXTPROC_DLLS=ONLY:D:\install\Oracle\product\11.2.0\dbhome_1\bin\oraclr11.dll")rn )rn )rnrnLISTENER =rn (DESCRIPTION_LIST =rn (DESCRIPTION =rn (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))rn )rn (DESCRIPTION =rn (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.106)(PORT = 1521))rn )rn )rnrnADR_BASE_LISTENER = D:\install\Oraclern[/code]rn报错信息:rn[code=java]rn org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappedStatementStrategy' defined in file [C:\Users\Max\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\iPlat4j3\WEB-INF\classes\spring\framework\applicationContext-ibatis.xml]: Invocation of init method failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io 异常: The Network Adapter could not establish the connection)rnCaused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io 异常: The Network Adapter could not establish the connection)rnCaused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io 异常: The Network Adapter could not establish the connection)rn at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:855)rn at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)rn at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:112)rn at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)rn at org.springframework.jdbc.core.support.JdbcDaoSupport.getConnection(JdbcDaoSupport.java:119)rn at com.baosight.iplat4j.core.sqldao.impl.NamedSqlDaoSpringJdbcImpl.getDbConnection(NamedSqlDaoSpringJdbcImpl.java:364)rn at com.baosight.iplat4j.core.sqldao.impl.NamedSqlDaoDiagnoseImpl.getDbConnection(NamedSqlDaoDiagnoseImpl.java:81)rn at com.baosight.iplat4j.ep.MappedStatementStrategyWithPreLoadImpl.init(MappedStatementStrategyWithPreLoadImpl.java:36)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1160)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1122)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:273)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)rn at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)rn at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)rn at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)rn at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)rn at java.util.concurrent.FutureTask.run(FutureTask.java:262)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connectionrn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)rn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)rn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)rn at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)rn at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:441)rn at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)rn at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)rn at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)rn at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)rn at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)rn at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)rn at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)rn ... 34 morern[/code]rn[b]基本可以确定是数据库问题或者是配置文件问题,因为之前用过是好的,换了一个数据库就不行了,而且plsql可以正常连接数据库[/b]
hive编程-JDBC方式连接hive
博主使用JDBC方式进行hive编程,hive环境为hive2.2.0,需要开启hiveserver模式,自带的server模式是hiveserver2,启动命令如下:(1)hive --service hiveserver2  (这种方式会使得hiveserver一直占用命令行,需要用Ctrl+C强制中断命令)(2)hive --service hiveserver2 &  (这个命令会...
hive笔记-使用JDBC操作hive
参考网址:https://cwiki.apache.org/confluence/display/Hive/HiveClient#HiveClient-JDBC其实根据官网的wiki即可实现,连代码都不用自己敲,但是有几个地方需要注意的。package com.hihi.hive; import java.sql.SQLException; import java.sql.Connection;...