Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addBatch and executeBatch #6

Open
krassimirkostadinov opened this issue Aug 18, 2015 · 2 comments
Open

addBatch and executeBatch #6

krassimirkostadinov opened this issue Aug 18, 2015 · 2 comments

Comments

@krassimirkostadinov
Copy link

Hi,

I have tried to enhance the package, adding the functions

addBatch(stmt::Union(JPreparedStatement, JCallableStatement)) = jcall(stmt, "addBatch", jint, Void, ())
executeBatch(stmt::Union(JPreparedStatement, JCallableStatement)) = jcall(stmt, "executeBatch", jint, Void, ())

In your jdbc.jl, then in Julia

ppstmt = prepareStatement(conn, "insert into tablename values (?,?)")
n=size(f)[1]
for i=1:n
    setString(ppstmt, 1, "One")
    setString(ppstmt, 2, "Two")
    addBatch(ppstmt)
end

Error message: "Type: anonymous: Expected Function, got Module"

@aviks
Copy link
Member

aviks commented Aug 19, 2015

The jcall lines don't look right. The third argument is the type of the return value, and the fourth argument is a tuple of the types of the java method parameters.

I think it should be the following (untested)

jcall(stmt, "addBatch", Void, ())
jcall(stmt, "executeBatch", Array{jint}, ())

@walter-weinmann
Copy link

walter-weinmann commented Oct 11, 2021

Hi @aviks

I am very interested in batch processing because of my OraBench project. Unfortunately I am not a Julia expert - nevertheless I tried to add the following to JDBC.jl:

"""
```
addBatch(stmt::Union{JPreparedStatement, JCallableStatement, JStatement})
```
Adds the given SQL command to the current list of commands based on a JPreparedStatement object, a JCallableStatement object or a JStatement object

### Args
* stmt: The JPreparedStatement object, JCallableStatement object or JStatement object

### Returns
None
"""
addBatch(stmt::Union{JPreparedStatement, JCallableStatement, JStatement}) = jcall(stmt, "addBatch", Nothing, ())

"""
```
executeBatch(stmt::Union{JPreparedStatement, JCallableStatement, JStatement})
```
Submits a batch of SQL commands based on a JPreparedStatement object, a JCallableStatement object or a JStatement object to the database for execution

### Args
* stmt: The JPreparedStatement object, JCallableStatement object or JStatement object

### Returns
An array of update counts containing one element for each command in the batch
"""
executeBatch(stmt::Union{JPreparedStatement, JCallableStatement, JStatement}) = jcall(stmt, "executeBatch", Array{jint}, ())

Unfortunately, I get the following error message when testing:

ERROR: LoadError: MethodError: no method matching ndims(::Type{Array{Int32,N} where N})
Closest candidates are:
  ndims(::Type{DataFrames.ColReplaceDataFrame}) at /home/travis/.julia/packages/DataFrames/vuMM8/src/other/broadcasting.jl:97
  ndims(::Base.Generator) at generator.jl:53
  ndims(::Number) at number.jl:67
  ...
Stacktrace:
 [1] signature(::Type) at /home/travis/.julia/packages/JavaCall/tjlYt/src/core.jl:463
 [2] method_signature(::Type) at /home/travis/.julia/packages/JavaCall/tjlYt/src/core.jl:437
 [3] jcall(::JavaObject{Symbol("java.sql.PreparedStatement")}, ::String, ::Type, ::Tuple{}) at /home/travis/.julia/packages/JavaCall/tjlYt/src/core.jl:242
 [4] executeBatch(::JavaObject{Symbol("java.sql.PreparedStatement")}) at /home/travis/build/walter-weinmann/JDBC.jl/src/JDBC.jl:69
 [5] top-level scope at /home/travis/build/walter-weinmann/JDBC.jl/test/runtests.jl:179
 [6] include at ./boot.jl:328 [inlined]
 [7] include_relative(::Module, ::String) at ./loading.jl:1105
 [8] include(::Module, ::String) at ./Base.jl:31
 [9] include(::String) at ./client.jl:424
 [10] top-level scope at none:6
in expression starting at /home/travis/build/walter-weinmann/JDBC.jl/test/runtests.jl:179
ERROR: Package JDBC errored during testing
Stacktrace:
 [1] pkgerror(::String, ::Vararg{String,N} where N) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/Pkg/src/Types.jl:113
 [2] #test#131(::Bool, ::Nothing, ::Cmd, ::Cmd, ::typeof(Pkg.Operations.test), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/Pkg/src/Operations.jl:1372
 [3] #test at ./none:0 [inlined]
 [4] #test#62(::Bool, ::Nothing, ::Cmd, ::Cmd, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(Pkg.API.test), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/Pkg/src/API.jl:253
 [5] (::Pkg.API.var"#kw##test")(::NamedTuple{(:coverage,),Tuple{Bool}}, ::typeof(Pkg.API.test), ::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at ./none:0
 [6] #test#58 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/Pkg/src/API.jl:233 [inlined]
 [7] (::Pkg.API.var"#kw##test")(::NamedTuple{(:coverage,),Tuple{Bool}}, ::typeof(Pkg.API.test)) at ./none:0
 [8] top-level scope at none:1
The command "julia --check-bounds=yes --color=yes -e "if VERSION < v\"0.7.0-DEV.5183\"; Pkg.test(\"${JL_PKG}\", coverage=true); else using Pkg; Pkg.test(coverage=true); end"" failed and exited with 1 during .0m
Your build has been stopped.

Can you please give me a hint - thank you very much.

My fork is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants