The Mail cause of this error is stating by the message itself 'String literal too long'. If you try to INSERT more than 4000 characters to a varchar2 field this error will occur. Another case where this may occur is if you try to update a CLOB field. CLOB field doesn't support update.
In Java if you try to execute PreparedStatement.executeUpdate() to INSERT or UPDATE CLOB field of ORACLE with more than 4000 characters, you'll get this error.
To avoid this use PreparedStatement.execute() methode to to INSERT CLOB field.
This may occur in other language also. And you can use same technique to avoid errors.
Happy programming.
Comment my blog/ email me for any problems related to this.
Java J2ME JSP J2EE Servlet Android
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Java Difference between Hashtable and Hashmap / Hashtable versus Hashmap
Both Hashtable and Hashmap are Hashtable implementation of java classes. Hashtable is a basic class of java 'Collection Framework' and Hashmap is a Hashtable implementa from Map interface.
The majore differences are described below...
1. Synchronous/asynchronous: Hashtable is synchronous and Hashmap is not synchronous by default.
2. null value as key: Hashtable does not support null value as hash key but Hasmap support it.
3. Faile-safe: Iterator of Hashmap is fail-safe but Enumeration of Hashtable is not failsafe.
Perhaps this will be able to eliminate any misconception about Hashtable and Hashmap
The majore differences are described below...
1. Synchronous/asynchronous: Hashtable is synchronous and Hashmap is not synchronous by default.
2. null value as key: Hashtable does not support null value as hash key but Hasmap support it.
3. Faile-safe: Iterator of Hashmap is fail-safe but Enumeration of Hashtable is not failsafe.
Perhaps this will be able to eliminate any misconception about Hashtable and Hashmap
Using Session in JSP
Session is very important in we programming. There are many use of session in web programming. Java servlet/ Jsp provide easy way to work with session.
See the following code...
<%
Vector users = new Vector();
users.add("ABC");
users.add("BCD");
users.add("CDE");
session.setAttribute("users", users);
%>
This will set the Vector object users to session with name users.
To get values from session we can do the following..
<%
Vector users = (Vector)getAttribute("users");
for(int i=0;i<users.size();i++)
out.print((String)users.get(i)+"<br >");
%>
In this way we can handle session in JSP/servlet.
For any query just add comment..
See the following code...
<%
Vector users = new Vector();
users.add("ABC");
users.add("BCD");
users.add("CDE");
session.setAttribute("users", users);
%>
This will set the Vector object users to session with name users.
To get values from session we can do the following..
<%
Vector users = (Vector)getAttribute("users");
for(int i=0;i<users.size();i++)
out.print((String)users.get(i)+"<br >");
%>
In this way we can handle session in JSP/servlet.
For any query just add comment..
JAVA: Accessing properties file(resource) inside jar
You can not load a properties file inside a jar as following way..
Properties props = new Properties();
props.load(new FileInputStream("conf.properties"));
In this case you have to use
Properties props = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("conf.properties");
props.load(in);
I hope this will help you. For any other query you can post question as comment.
Properties props = new Properties();
props.load(new FileInputStream("conf.properties"));
In this case you have to use
Properties props = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("conf.properties");
props.load(in);
I hope this will help you. For any other query you can post question as comment.
A way in java to user bangla number format
The following method will format a double number as thousand lac crore method
with 2 digits after decimal point.
for example 1234567890.987654321 will be formatted as
1,23,45,67,890.99
public static String banglaFormat(double number){
DecimalFormat format1 = new DecimalFormat("#,##0.00");
DecimalFormat format2 = new DecimalFormat("#,##");
DecimalFormat format3 = new DecimalFormat("000.00");
if(number<1000)
return format1.format(number);
double num2 = number/1000;
double num3 = number%1000;
return format2.format(num2)+","+format3.format(num3);
}
with 2 digits after decimal point.
for example 1234567890.987654321 will be formatted as
1,23,45,67,890.99
public static String banglaFormat(double number){
DecimalFormat format1 = new DecimalFormat("#,##0.00");
DecimalFormat format2 = new DecimalFormat("#,##");
DecimalFormat format3 = new DecimalFormat("000.00");
if(number<1000)
return format1.format(number);
double num2 = number/1000;
double num3 = number%1000;
return format2.format(num2)+","+format3.format(num3);
}
Java batch sql execution example
Here is an example of execution batch sql.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* This is a demo class for batch execution example
*
* @author Sharif Uddin
*
*/
public class BatchExmpl {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void batchTest(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection( "jdbc:mysql://localhost:3307/mysql", "root", "");
String sql = "INSER INTO mytab(id,name) VALUES(?,?)";
PreparedStatement pstmt = connection.prepareStatement(sql);
for(int i=1;i<10;i++){
pstmt.setLong(1, i);
pstmt.setString(2, "Name_"+i);
pstmt.addBatch();
}
int updateCount[] = pstmt.executeBatch();
for(int i=0;i
System.out.println(updateCount[i]);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* This is a demo class for batch execution example
*
* @author Sharif Uddin
*
*/
public class BatchExmpl {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void batchTest(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection( "jdbc:mysql://localhost:3307/mysql", "root", "");
String sql = "INSER INTO mytab(id,name) VALUES(?,?)";
PreparedStatement pstmt = connection.prepareStatement(sql);
for(int i=1;i<10;i++){
pstmt.setLong(1, i);
pstmt.setString(2, "Name_"+i);
pstmt.addBatch();
}
int updateCount[] = pstmt.executeBatch();
for(int i=0;i
System.out.println(updateCount[i]);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
}
}
Subscribe to:
Posts (Atom)