简体   繁体   中英

Run dbisql in Java Program

I build a Sybase-IQ 16.0 on red-hat 7 server.

I try to use dbisql for bulk load data in Sybase.

And I already successful by command in Sybase server:

dbisql -nogui -c "UID=DBA;PWD=sql;DWN=iqtry;host=172.16.50.137:2643;" -onerror continue READ /EXT_LOAD/Load_Test_Data.SQL

But I need to do this in java program from project requirement, so my program as below:

import java.io.*;
import java.sql.*;
import java.util.*;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
public static void main(String[] args) throws SQLException {

String dburl = "dbisql -nogui -c 'UID=DBA;PWD=sql;DWN=iqtry;host=172.16.50.137:2643;' -onerror continue READ /sybase/IQ_LOAD/load_DBA.atest.sql";

// Connect to Sybase Database
Connection con = DriverManager.getConnection(dburl);
Statement statement = con.createStatement();
}}

And I can compile in Syabse Server, but when I run this class, I got following error:

Exception in thread "main" java.sql.SQLException: No suitable driver found for

jdbc:sqlanywhere:uid=DBA;pwd=sql;eng=iqtry;database=atest;links=tcpip(host=172.

16.50.137,2643)

at java.sql.DriverManager.getConnection(DriverManager.java:689)

at java.sql.DriverManager.getConnection(DriverManager.java:270)

at Test.main(ConnectIQ.java:30)

From my problem, I have try to set classpath in my current path

set classpath = ./sybase/IQ-16_0/java/sajdbc4.jar

set classpath = ./sybase/IQ-16_0/java/jconn4.jar

But all is can't work.

The dbisql utility is a command line utility and should not be used in conjunction with Java. It is meant to be used through Shells like Bash, or, in a GUI environment.

sajdbc4.jar file is the JDBC driver for SAP IQ. As you've mentioned already about it being in the CLASSPATH , it is better to use its IQDataSource class which implements DataSource Interface from JDBC standard.

A simple code would be:

IQDataSource iqDataSource = new IQDataSource();
iqDataSource.setURL(jdbcUrl);
iqDataSource.setUser(username);
iqDataSource.setPassword(password);

Another hint: remember, each release of SAP IQ ties with a specific build of JDBC driver. Verify you are using the right version target for the right platform.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM