Apache Drill JDBC connectivity through java code is giving error:Failure in connecting to Drill: oadd.org.apache.drill.exec.rpc.RpcException - jdbc

i am trying drill-jdbc connectivity through java code.
Error is:-
java.sql.SQLException: Failure in connecting to Drill: oadd.org.apache.drill.exec.rpc.RpcException: CONNECTION : java.net.ConnectException: Connection refused: no further information: localhost/127.0.0.1:31010
So the steps followed are below:-
wget http://www-eu.apache.org/dist/drill/drill-1.12.0/apache-drill-1.12.0.tar.gz
tar -xvf apache-drill-1.12.0.tar.gz
cd apache-drill-1.12.0
cd bin
./drillbit.sh start -Ddrill.exec.http.port=8765
To check check its running under zookeeeper
cd /usr/hdp/current/zookeeper-client
./zkCli.sh
ls /drill
In apache-drill-1.12.0/bin
started drill-localhost # ./drill-localhost
received contents "OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0 apache drill 1.12.0"
normal database queries were working properly
is there any dependancy between jdk -version?
Java Code:-
import java.sql.*;
public class DrillJDBCExample {
static final String JDBC_DRIVER = "org.apache.drill.jdbc.Driver";
static final String DB_URL = "jdbc:drill:drillbit=localhost:";//"jdbc:drill:zk=localhost:2181";
//"jdbc:drill:drillbit=localhost";
static final String USER = "admin";
static final String PASS = "admin";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
/* Class.forName("org.apache.drill.jdbc.Driver");
Connection connection =DriverManager.getConnection("jdbc:drill:drillbit=127.0.0.1:8765");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("SELECT * from cp.`employee`");
while(rs.next()){
System.out.println(rs.getString(1));
}
}*/
Connection conn = null;
Statement stmt = null;
try{
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL,USER,PASS);
stmt = conn.createStatement();
// Perform a select on data in the classpath storage plugin.
String sql = "select employee_id,first_name,last_name from cp.`employee.json`";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
int id = rs.getInt("employee_id");
String first = rs.getString("first_name");
String last = rs.getString("last_name");
System.out.print("ID: " + id);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}
rs.close();
stmt.close();
conn.close();
} catch(SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch(Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
try{
if(stmt!=null)
stmt.close();
} catch(SQLException se2) {
}
try {
if(conn!=null)
conn.close();
} catch(SQLException se) {
se.printStackTrace();
}
}
}
}
Error Logs:-
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.sql.SQLException: Failure in connecting to Drill: oadd.org.apache.drill.exec.rpc.RpcException: HANDSHAKE_COMMUNICATION : Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
at org.apache.drill.jdbc.impl.DrillConnectionImpl.<init>(DrillConnectionImpl.java:162)
at org.apache.drill.jdbc.impl.DrillJdbc41Factory.newDrillConnection(DrillJdbc41Factory.java:64)
at org.apache.drill.jdbc.impl.DrillFactory.newConnection(DrillFactory.java:69)
at oadd.net.hydromatic.avatica.UnregisteredDriver.connect(UnregisteredDriver.java:126)
at org.apache.drill.jdbc.Driver.connect(Driver.java:72)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.mapr.drill.DrillJDBCExample.main(DrillJDBCExample.java:29)
Caused by: oadd.org.apache.drill.exec.rpc.RpcException: HANDSHAKE_COMMUNICATION : Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
at oadd.org.apache.drill.exec.client.DrillClient$FutureHandler.connectionFailed(DrillClient.java:675)
at oadd.org.apache.drill.exec.rpc.user.QueryResultHandler$ChannelClosedHandler.connectionFailed(QueryResultHandler.java:389)
at oadd.org.apache.drill.exec.rpc.BasicClient$ConnectionMultiListener$HandshakeSendHandler.failed(BasicClient.java:254)
at oadd.org.apache.drill.exec.rpc.RequestIdMap$RpcListener.setException(RequestIdMap.java:134)
at oadd.org.apache.drill.exec.rpc.RequestIdMap$SetExceptionProcedure.apply(RequestIdMap.java:74)
at oadd.org.apache.drill.exec.rpc.RequestIdMap$SetExceptionProcedure.apply(RequestIdMap.java:64)
at oadd.com.carrotsearch.hppc.IntObjectHashMap.forEach(IntObjectHashMap.java:692)
at oadd.org.apache.drill.exec.rpc.RequestIdMap.channelClosed(RequestIdMap.java:58)
at oadd.org.apache.drill.exec.rpc.RemoteConnection.channelClosed(RemoteConnection.java:175)
at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:167)
at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:146)
at oadd.io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:680)
at oadd.io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:567)
at oadd.io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:406)
at oadd.io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:82)
at oadd.io.netty.channel.AbstractChannel$CloseFuture.setClosed(AbstractChannel.java:943)
at oadd.io.netty.channel.AbstractChannel$AbstractUnsafe.doClose0(AbstractChannel.java:592)
at oadd.io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:584)
at oadd.io.netty.channel.DefaultChannelPipeline$HeadContext.close(DefaultChannelPipeline.java:1099)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
at oadd.io.netty.channel.ChannelOutboundHandlerAdapter.close(ChannelOutboundHandlerAdapter.java:71)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
at oadd.io.netty.channel.ChannelDuplexHandler.close(ChannelDuplexHandler.java:73)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:615)
at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:600)
at oadd.io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:466)
at oadd.org.apache.drill.exec.rpc.RpcExceptionHandler.exceptionCaught(RpcExceptionHandler.java:39)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelHandlerAdapter.exceptionCaught(ChannelHandlerAdapter.java:79)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:253)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:275)
at oadd.io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:809)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:341)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
at oadd.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:242)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
at oadd.io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at oadd.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)
at oadd.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
at oadd.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:847)
at oadd.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at oadd.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at oadd.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at oadd.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at java.lang.Thread.run(Unknown Source)
Caused by: oadd.org.apache.drill.exec.rpc.ChannelClosedException: Channel closed /127.0.0.1:60181 <--> localhost/127.0.0.1:8765.
at oadd.org.apache.drill.exec.rpc.RpcBus$ChannelClosedHandler.operationComplete(RpcBus.java:166)
... 52 more
Followed documents are:-
1) https://drill.apache.org/docs/
2) https://community.hortonworks.com/articles/10551/apache-drill-unofficial-introduction.html

Related

Unable to connect hive in kerberos mode

Here is the code to connect to hive in kerberos mode
import java.sql.*;
import org.apache.hadoop.security.UserGroupInformation;
public class hive2 {
public static void main (String args[]) {
try {
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab("hive/ambari2012.howard2012.local#HOWARD2012.LOCAL", "/etc/security/keytabs/hive.service.keytab");
Class.forName("org.apache.hive.jdbc.HiveDriver");
System.out.println("getting connection");
Connection con = DriverManager.getConnection("jdbc:hive2://ambari2012:10000/;principal=hive/ambari2012.howard2012.local#HOWARD2012.LOCAL");
System.out.println("got connection");
con.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
the issue is doesnt matter what keytab I pass it's always giving the below error -
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
java.io.IOException: Login failure for hive/ambari2012.howard2012.local#HOWARD2012.LOCAL from keytab /etc/security/keytabs/hive.service.keytab
at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:921)
at hive.connect.java.hive.connect.java.App.main(App.java:21)
Caused by: javax.security.auth.login.LoginException: Unable to obtain password from user
I don't think it's even trying to check if the right keytab is given to it.
How should I ensure it's reading the correct keytab file and also if the keytab file is not present it should give unable to locate the keytab
Please let me know if I have to copy the keytab ,krb files in my local machine
I don't think you can connect to a kerberized HIVE this way.
Try using a JAAS file https://docs.oracle.com/javase/7/docs/technotes/guides/security/jgss/tutorials/LoginConfigFile.html
and add the 2 following properties to your JVM :
-Djavax.security.auth.useSubjectCredsOnly=False
-Djava.security.auth.login.config=jaas.conf
Sample file jaas.conf :
com.sun.security.jgss.krb5.initiate
{ com.sun.security.auth.module.Krb5LoginModule required
useKeyTab =true
useTicketCache =false
doNotPrompt =true
principal ="hive/ambari2012.howard2012.local#HOWARD2012.LOCAL"
keyTab ="/etc/security/keytabs/hive.service.keytab"
debug =false;
};
Client
{ com.sun.security.auth.module.Krb5LoginModule required
useKeyTab =true
useTicketCache =false
doNotPrompt =true
principal ="hive/ambari2012.howard2012.local#HOWARD2012.LOCAL"
keyTab ="/etc/security/keytabs/hive.service.keytab"
debug =false;
};
I was missing jar files so if you add all jar files it's fine, here is the complete code
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
public class App {
private static Connection hiveConnection;
// get Hive Connection
public static void main(String [] args) throws IOException, SQLException {
String principal="principal";
String keytab="keytab";
Runtime rt = Runtime.getRuntime();
try{ Process p = rt.exec("kinit -k -t " + keytab + " " + principal);
p.waitFor(); }
catch(InterruptedException exception)
{
System.out.println("wait for threw an exception - it was interrupted");
exception.printStackTrace();
}
catch (IOException exception){
System.out.println("Exception in running kinit process") ;
exception.printStackTrace();
}
System.out.println("Preparing Hive connection1");
Configuration conf = new Configuration();
System.setProperty("javax.security.auth.useSubjectCredsOnly","false");
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab(principal, keytab);
// Hive Connection
try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
if(hiveConnection == null) {
hiveConnection = DriverManager.getConnection("jdbc:hive2://host:10000/;principal=principal;auth=kerberos;kerberosAuthType=fromSubject");
// return hiveConnection;
System.out.println("Got Connection");
} else {
//return hiveConnection;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
// return null;
} catch (SQLException e) {
e.printStackTrace();
// return null;
}
}
}

FTPClient SocketTimeoutException Read timed out

I have a given FTP Server. I can connect to the server per WinSCP and other programs. I had allready a connection via Java to the server but after a while I can not connect. Per WinSCP I can connect the whole time. Now there is the question if the server is the reason of the problem or the program.
There is my Code:
private FTPClient ftpClient = null;
public FtpServerConnector() throws Exception {
ftpClient = new FTPClient();
ftpClient.connect(url);
ftpClient.login(username, password);
}
public List<FTPFile> getDirectory(String directoryPath) throws Exception {
FTPFile[] files = ftpClient.listFiles(directoryPath);
List<FTPFile> result = new ArrayList<FTPFile>();
for (FTPFile ftpFile : files) {
if (ftpFile.getTimestamp().getTime().getTime() >= Long.parseLong("1451606400000")) {
result.add(ftpFile);
}
}
return result;
}
public static void main(String[] args) {
try {
FtpServerConnector ftpServerConnector = new FtpServerConnector();
List<FTPFile> folders = ftpServerConnector.getDirectory("/");
for (FTPFile ftpFile : folders) {
System.out.println(ftpFile.getName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
There is the Exception:
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.read(BufferedReader.java:182)
at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:314)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
at org.apache.commons.net.ftp.FTP.port(FTP.java:932)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:812)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:759)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3293)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3271)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930)
at com.kianaanalytics.eventManagement.util.FtpServerConnector.getDirectory(FtpServerConnector.java:38)
at com.kianaanalytics.eventManagement.util.ImportWorker.getAllNewFairFolders(ImportWorker.java:19)
It appeared that the directory has "too many" files inside of it - enough to be too long to throw SocketTimeout Exception.
You didn't mention what version are you using in FTP-client,
This issue seems to handle something similar - I would consider upgrading version if its lower than 3.4.
https://issues.apache.org/jira/browse/NET-552

Connecting to a SQL Server 2000 db from Java

I am receiving an error that I did see on your site, but as a novice java coder I think that I flubbed my implementation of the solution.
I am getting a message
"SQL Server version 8 is not supported by this driver. ClientConnectionId:602d619d-c033-41d0-9109-80f56e3ab9b3"
I am using Eclipse Mars 1
The database is a sql server 2000, so I downloaded sqljdbc.jar from the Microsoft site as suggested by an earlier question. I loaded it to c:\temp and added that to the CLASSPATH and rebooted.
code snippet reads:
package texasLAMPConversion;
import java.sql.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class TexasLAMPConversion {
public static void main(String[] args) {
// TODO Auto-generated method stub
String host = "jdbc:sqlserver://serverName\\instanceName";
String uName = "*********";
String uPass = "*********";
Connection conn = null;
try {
conn = DriverManager.getConnection(host, uName,uPass);
if (conn != null) { System.out.println("Connected to the database");
}
} catch (SQLException ex) {
System.out.println(ex.getMessage() );
ex.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
FileWriter fw= null;
File file =null;
try {
file=new File("C:/temp/generated_stmts_update_t_customer_master.sql");
if(!file.exists()) {
file.createNewFile();
}
fw = new FileWriter(file);
}catch (IOException e) {
e.printStackTrace();
}
String oldKey = "8000001234", newKey = "8";
int lenAcct = 10;
oldKey = ReformatOldAcct(lenAcct, oldKey );
newKey = leftZeroAcct(lenAcct, newKey);
System.out.println("oldkey = " + oldKey + " and newKey = " + newKey);
}
private static String ReformatOldAcct(int lenAcct, String oldKey) {
// TODO Auto-generated method stub
String reformatedAcct = "";
reformatedAcct = "0" + oldKey.substring(2, lenAcct);
return (reformatedAcct);
}
private static String leftZeroAcct(int lenAcct, String acctNo) {
// TODO Auto-generated method stub
int index =0;
int currentLengthAcct;
String leadingZero = "";
currentLengthAcct = acctNo.length();
while (index < (lenAcct -currentLengthAcct) ) {
leadingZero = '0' + leadingZero;
index ++;
}
return (leadingZero + acctNo);
}
}
and it is throwing this complete message
Apr 19, 2016 11:29:44 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
WARNING: ConnectionID:1 ClientConnectionId: 602d619d-c033-41d0-9109-80f56e3ab9b3 Server major version:8 is not supported by this driver.
Apr 19, 2016 11:29:44 AM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
WARNING: ConnectionID:1 ClientConnectionId: 602d619d-c033-41d0-9109-80f56e3ab9b3 Server major version:8 is not supported by this driver.
com.microsoft.sqlserver.jdbc.SQLServerException: SQL Server version 8 is not supported by this driver. ClientConnectionId:602d619d-c033-41d0-9109-80f56e3ab9b3com.microsoft.sqlserver.jdbc.SQLServerException: SQL Server version 8 is not supported by this driver. ClientConnectionId:602d619d-c033-41d0-9109-80f56e3ab9b3
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2226) at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2226)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2210)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2210)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:2095)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:2095)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1799)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1799)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1454)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1454)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1285)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1285)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1131)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1131)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at texasLAMPConversion.TexasLAMPConversion.main(TexasLAMPConversion.java:20)
at texasLAMPConversion.TexasLAMPConversion.main(TexasLAMPConversion.java:20)
SQL Server version 8 is not supported by this driver. ClientConnectionId:602d619d-c033-41d0-9109-80f56e3ab9b3
SQL Server version 8 is not supported by this driver. ClientConnectionId:602d619d-c033-41d0-9109-80f56e3ab9b3
Any thoughts for a novice java programmer moving away from PowerBuilder?

java.sql.SQLSyntaxErrorException: The class 'TempSP' does not exist or is inaccessible

I am trying to create stored procedure in derby database using java.
public class TestDrive {
public static void main (String[] args) throws SQLException, ClassNotFoundException{
Connection conn = null;
CallableStatement stmt = null;
try {
try{
Class.forName("org.apache.derby.jdbc.ClientDriver").;
} catch(ClassNotFoundException e){
System.out.println("Can't load the database driver");
return;
}
conn = DriverManager.getConnection("jdbc:derby://localhost:1527/Connections_DB", "Connections_DB", "KaayRey");
stmt = conn.prepareCall("CALL NameOFstoreProcedure4( ?, ? )");
stmt.setString(1, "Kitu");
stmt.setString(2, "KaayChalay");
stmt.execu`enter code here`te();
} finally {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}
}
} //END OF CLASS TestDrive.java
TempSP.java Code:-
public class TempSP {
public static void NameOFSP(String uname, String upass)throws SQLException {
PreparedStatement stmt = null;
ResultSet res = null;
String message = null ;
try{
try{`enter code here`
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch(ClassNotFoundException e){
System.out.println("Can't load the database driver");
return;
}
String dbURL = "jdbc:derby://localhost:1527/Connections_DB";
Connection conn = DriverManager.getConnection(dbURL, "Connections_DB", "KaayRey");
Stri`enter code here`ng sql = "INSERT INTO USERS2(USER_NAME, USER_PASSWORD) VALUES(?, ?)";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uname);
stmt.setString(2, upass);
int row = stmt.executeUpdate(sql);
}catch (SQLException ex) {
message = "ERROR 1 : " + ex.getMessage();
ex.printStackTrace();
}
}
} // END OD TempSP.java
But when I run run my TestDrive.java file it will gives me following error:-
"Exception in thread "main" java.sql.SQLSyntaxErrorException: The class 'TempSP' does not exist or is inaccessible. This can happen if the class is not public.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Connection.prepareCall(Unknown Source)
at FriendsConnectionPack.TestDrive.main(TestDrive.java:34)
Caused by: org.apache.derby.client.am.SqlException: The class 'TempSP' does not exist or is inaccessible. This can happen if the class is not public.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readPrepare(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPrepare(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepare_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepare(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
at org.apache.derby.client.am.Connection.prepareCallX(Unknown Source)
... 2 more
Caused by: org.apache.derby.client.am.SqlException: Java exception: 'TempSP: java.lang.ClassNotFoundException'.
... 13 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)"
Derby Stored Procedure Code As Follows:-
CREATE PROCEDURE NameOFstoreProcedure5(User_Name VARCHAR(50), User_Password VARCHAR(20))
PARAMETER STYLE JAVA READS SQL DATA LANGUAGE JAVA EXTERNAL NAME
'FriendsConnectionPack.TempSP.NameOFSP'
I encountered the same problem and the solution was setting the stored procedure's code in a jar file and then using the derby's systems procedures to register the jar and setting the derby's class path as shown next
To add a jar to Derby:
CALL sqlj.install_jar('PATH TO JAR FILE', 'DATABASE.IDENTIFIER FOR THE JAR', 0)
To add the jar to derby's internal classpath
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(
'derby.database.classpath',
'colonSeparatedJarFiles')
Hope this helps someone

Getting an error when try to connect to Oracle java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

i am trying connect to Oracle Database through following program. but throws an error
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver "
only SQL developer client is installed on my machine whereas Actual data base is store on Server. Please help on resolving the issue
package test;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
public class DBConnection {
public static void main(String[] argv) {
System.out.println("-------- Oracle JDBC Connection Testing ------");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("Oracle JDBC Driver Registered!");
Connection connection = null;
enter code here
try {
connection = DriverManager.getConnection(
"jdbc:oracle:thin:#hostname:5800:SID", "user","password");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
}
}
Add your Oracle JDBC Driver jar to the classpath
Can download the driver for your Oracle Database Version from here

Resources