to work with database...

B

Bumsys

I want to write file to database sybase. I run the following code:

public class TestSybase {
public static void main( String[] args ) {
try {
// Connect to the database

Class.forName("com.sybase.jdbc3.jdbc.SybDriver");
String url = "jdbc:sybase:Tds:10.64.3.27:5000/au12";
Connection con = DriverManager.getConnection(url, "sa",
"");
// Execute the SQL statement
Statement stmt = con.createStatement();

String query = "insert into au_log (logfile) values (?)";
PreparedStatement ps = con.prepareStatement(query);
File file = new File("C:\\Temp\\tttt.rar");
int len = (int) file.length();
if (!file.exists()) {
ps.setNull(1, Types.LONGVARBINARY);
} else if (file.exists() && len == 0) {
ps.setNull(1, Types.LONGVARBINARY);
} else {
InputStream in = new FileInputStream(file);
ps.setBinaryStream(1, in, len);
}

int numberOfRows = ps.executeUpdate();
System.out.println("rows: " + numberOfRows);
ps.close();
stmt.close();
}
catch( Exception e ) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}

If I write a small file to database sybase all is ok. But if a big
file I have error:
com.sybase.jdbc3.jdbc.SybSQLException: There is not enough procedure
cache to run this procedure, trigger, or SQL batch. Retry later, or
ask your SA to reconfigure ASE with more procedure cache.

There is not enough procedure cache to run this procedure, trigger, or
SQL batch. Retry later, or ask your SA to reconfigure ASE with more
procedure cache.

at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.updateLoop(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.executeUpdate(Unknown Source)
at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeUpdate(Unknown
Source)
at test.TestSybase.main(TestSybase.java:96)

I change procedure cache but I have this error again. What can do that
write a big file to sybase?
 
R

Roedy Green

"insert into au_log (logfile) values (?)";

Whatever it would take to configure more procedure space would be
specific to you SQL engine. You won't do it through JDBC. You did not
say what engine you are using.

I am not familiar with that syntax "au_log (logfile)". I would
double check that.

Most databases have a command line interface you can use to perform
experiments. Get your SQL working in that experimental mode before
you add the complexity of Java and JDBC.
 
A

Arne Vajhøj

I want to write file to database sybase. I run the following code:
If I write a small file to database sybase all is ok. But if a big
file I have error:
com.sybase.jdbc3.jdbc.SybSQLException: There is not enough procedure
cache to run this procedure, trigger, or SQL batch. Retry later, or
ask your SA to reconfigure ASE with more procedure cache.

There is not enough procedure cache to run this procedure, trigger, or
SQL batch. Retry later, or ask your SA to reconfigure ASE with more
procedure cache.

at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
I change procedure cache but I have this error again. What can do that
write a big file to sybase?

It seems as if you have not increased procedure cache enough.

This is a pure Sybase configuration problem not a Java or JDBC problem.

Arne
 
A

Arne Vajhøj

Roedy said:
Whatever it would take to configure more procedure space would be
specific to you SQL engine. You won't do it through JDBC. You did not
say what engine you are using.

Actually he did say that he was using Sybase.
I am not familiar with that syntax "au_log (logfile)". I would
double check that.

No ned to.

It is standard SQL syntax to specify column names in an INSERT.

Arne
 
E

EricF

I want to write file to database sybase. I run the following code:

public class TestSybase {
public static void main( String[] args ) {
try {
// Connect to the database

Class.forName("com.sybase.jdbc3.jdbc.SybDriver");
String url = "jdbc:sybase:Tds:10.64.3.27:5000/au12";
Connection con = DriverManager.getConnection(url, "sa",
"");
// Execute the SQL statement
Statement stmt = con.createStatement();

String query = "insert into au_log (logfile) values (?)";
PreparedStatement ps = con.prepareStatement(query);
File file = new File("C:\\Temp\\tttt.rar");
int len = (int) file.length();
if (!file.exists()) {
ps.setNull(1, Types.LONGVARBINARY);
} else if (file.exists() && len == 0) {
ps.setNull(1, Types.LONGVARBINARY);
} else {
InputStream in = new FileInputStream(file);
ps.setBinaryStream(1, in, len);
}

int numberOfRows = ps.executeUpdate();
System.out.println("rows: " + numberOfRows);
ps.close();
stmt.close();
}
catch( Exception e ) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}

If I write a small file to database sybase all is ok. But if a big
file I have error:
com.sybase.jdbc3.jdbc.SybSQLException: There is not enough procedure
cache to run this procedure, trigger, or SQL batch. Retry later, or
ask your SA to reconfigure ASE with more procedure cache.

There is not enough procedure cache to run this procedure, trigger, or
SQL batch. Retry later, or ask your SA to reconfigure ASE with more
procedure cache.

at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.updateLoop(Unknown Source)
at com.sybase.jdbc3.jdbc.SybStatement.executeUpdate(Unknown Source)
at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeUpdate(Unknown
Source)
at test.TestSybase.main(TestSybase.java:96)

I change procedure cache but I have this error again. What can do that
write a big file to sybase?

I wonder if you'd be better off asking this in a sybase group. Once you start
dealing with BLOBs, which is what you are dealing with, you need to make sure
you are using the correct datatype - and these are proprietary - as well as
the corresponding data type in jdbc, also dependant on the vendor's driver
implementation.

The google search 'sybase jdbc blob' had a number of hits. Try it.

If I knew Sybase I'd try to help.

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top