This question already has answers here:
Insert CLOB into Oracle database
(6 answers)
Oracle Sql Developer "string literal too long" error
(5 answers)
How do I store a string longer than 4000 characters in an Oracle Database using Java/JDBC?
(4 answers)
Closed 4 years ago.
when I'm trying to insert blob in database having more than 4000 characters I'm getting fallowing error can anyone help on this.is there any way other than procedures to insert data :
Error report -
SQL Error: ORA-01704: string literal too long
01704. 00000 - "string literal too long"
*Cause: The string literal is longer than 4000 characters.
*Action: Use a string literal of at most 4000 characters.
Longer values may only be entered using bind variables
Instead of setString use setCharacterStream (for instance).
Of course assuming you are already using a PreparedStatement:
try (PreparedStatement stmt = conn.prepareStatement(someSql)) {
String large = String.format("%-4001s", "xxx");
StringReader reader = new StringReader(large);
stmt.setCharacterStream(1, reader, large.length());
stmt.setLong(2, someId);
int updateCount = stmt.executeUpdate();
}
Related
This question already has answers here:
PostgreSQL "Column does not exist" but it actually does
(6 answers)
Error: Column does not exist
(1 answer)
What's the problem with deleting a row from database?
(1 answer)
Java SQL "ERROR: Relation "Table_Name" does not exist"
(4 answers)
Closed 3 years ago.
I am using a Java PreparedStatement object to insert rows into a Postgres database table. (my code is below:)
...
// define values to insert
LocalDateTime localDateTime = LocalDateTime.now();
int num = 3;
double frac = 0.8;
//create PreparedStatement
PreparedStatement st = conn.prepareStatement("INSERT INTO TABLE_Final_Records(Datetime, Number_n, Fraction_f)"
+ "VALUES (?,?,?)" );
// set placeholder ("?") values as Postgres types
st.setObject(1, localDateTime);
st.setInt(2, num);
st.setDouble(3, frac);
// execute statement
st.executeUpdate();
st.close();
...
However, when I execute the above code I get the error (via a toString() of a caught SQLException):
org.postgresql.util.PSQLException: ERROR: relation
"table__final__records" does not exist.
Where each uppercase character specified in the code above appears as lower case in the text of the thrown exception.
If I manually rename the database table to be all lower case, the error is eliminated, without changing the code. However it is replaced with:
org.postgresql.util.PSQLException: ERROR: column "datetime" of
relation "table_final_records" does not exist
An obvious work-around would be to manually convert all uppercase characters in all the table and column names in the Postgres database to lower case, however I would like to know how to force case-sensitivity on such statements so that PostgreSQL database table & column names with uppercase characters can be properly recognized and updated.
Thanks
You could work around the issue by quoting the identifiers in the query:
PreparedStatement st = conn.prepareStatement(
"INSERT INTO \"TABLE_Final_Records\"(\"Datetime\", \"Number_n\", \"Fraction_f\")"
+ " VALUES (?,?,?)"
);
But bottom line: the issue that you are getting denotes that your database table and columns were created with double quotes surrounding the idenfiers. Generally, you want to avoid quoting the identifiers when you declare them, since this makes them case sensitive - which, as you are experiencing, makes writing query tedious and lengthy.
This question already has answers here:
How do I store a string longer than 4000 characters in an Oracle Database using Java/JDBC?
(4 answers)
Closed 4 years ago.
I am facing problems to store CLOB data through JDBC to Oracle 9i database. I am using PreparedStatement and setting the data as setString(index, value). The value is a large XML string. The driver I am using is ojdbc14.jar. Still I am getting an error saying " java.lang.Exception: Data size bigger than max size for this type: 4723".
My XML is not so big that it will not fit in CLOB field. Still getting this error. Please help.
I searched various sites it it did not solve the problem, the setClob() method is not supported by ojdbc14 driver.
The XML probably isn't too big for a CLOB (4GB!) but is for using setString (4000 characters). The textbook solution would probably be to use the setCharacterStream method instead:
PreparedStatement ps = ...;
String xml = "<xml>somve verly long data... </xml>";
ps.setCharacterStream(1, new StringReader(xml), xml.length());
This question already has answers here:
How to see PL/SQL Stored Function body in Oracle
(3 answers)
Closed 5 years ago.
I need to read the contents(text inside a stored procedure) of a stored procedure of a particular schema from a Java program.
Example. suppose I have a sp in oracle named mySp.
I need to read the text inside the sp.
How i can achieve this from a java program.
I think you can use something like this..Better refer JDBC MetaData API..Hope this helps
http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html
DatabaseMetaData dbMetaData = conn.getMetaData();
ResultSet rs = dbMetaData.getProcedureColumns(conn.getCatalog(),
null,
"mySp",
"");
while(rs.next()) {
/
}
This question already has answers here:
Passing parameter to Cassandra CQL query using DataStax client
(2 answers)
Closed 9 years ago.
I have Java code to access and process data in Cassandra. How do I pass a Java variable to Cassandra CQL query written in Java. Here is the code:
My code goes like this:
itemname="Item01";
com.datastax.driver.core.PreparedStatement result =
session.execute("select itemname from demodb.retail_transaction where itemnamw = itemname;");
But it gives the following error:
no viable alternative at input ';'
i think you should bind your variables to the prepared statement like this:
itemname="Item01";
itemtype="type01";
com.datastax.driver.core.PreparedStatement result =
session.execute("select itemname from demodb.retail_transaction where itemnamw = ? and
itemtype =?;");
BoundStatement boundStatement = new BoundStatement(statement);
ResultSet results = session.execute(boundStatement.bind(
itemname,itemtype));
This question already has answers here:
Get query from java.sql.PreparedStatement [duplicate]
(8 answers)
Closed 9 years ago.
When we create a PreparedStatement we use '?' chars to then be replaced by setted parameters.
How can we see the final SQL string after these parameters are set?
There is no final SQL string, the version with placeholders is what is actually sent to server. The data is sent completely separately from it as you execute queries on the prepared statement.
You can log the string with placeholders, and then each dataset individually.
Your code could combine them in the log to an actual SQL string if that's what you want:
String query = "SELECT a FROM b WHERE c = ?";
...
pstmt.setString(1, "asd");
logSQL( query, "asd");
logSQL would then actually log "SELECT a FROM b WHERE c = 'asd'". Could be that someone has actually implemented this before...
The easiest way (that works with any JDBC driver) is to use log4jdbc. It's a proxy that wraps the driver, creates a readable SQL string by combining the SQL and its parameters and logs it, then passes the SQL and parameters on to the underlying driver.