|
This isn't really a restriction of Hashtable. If your Hashtable contains a mutable object then you can update that object in situ with no problem, no need to do another put to ht. But, if the object is immutable then you cannot update it. You need to create a new value and put this to ht.
Things are a little more complicated in your case, because you also have autoboxing going on, which means that you are implicitly swapping between an Integer object and an integer primitive at various points in your code, so a new object is being created and will need to be put back into the Hashtable. But basically, it boils down to the fact that Integer is immutable.
|
|
|
|
|
Hi there !
I used bellow code to insert record to MS Access and get record from MS Access.
But i could insert or get correctly UTF8 string ?
Collapse
I have inserted người việt nam but it stored in MS Access like ng??i vi?t nam
Have you got any ideas?
Thanks in advance!
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
public class AccessUtil {
public static String url = "d:/utf-8.mdb";
private static Connection con_access ;
private static Connection getConnection() throws Exception {
Driver d = (Driver)Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
con_access = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + url +";charSet = UTF8");
return con_access;
}
public static Connection getConAccess(){
try
{
if( con_access == null ){
con_access = getConnection();
}
else if( con_access.isClosed() )
{
con_access = getConnection();
}
}catch(Exception e){
e.printStackTrace() ;
}
return con_access ;
}
public static void main(String[] args) {
try {
insertTest( "người việt nam", "người việt nam");
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean insertTest( String u1, String u2 )throws Exception {
Connection con = null ;
try{
con = AccessUtil.getConAccess() ;
Statement s = con.createStatement();
con.setAutoCommit(false);
String sql = " insert into tbl_test(u1,u2) values(?,?) " ;
PreparedStatement pstm = con.prepareStatement( sql ) ;
pstm.setString(1, u1);
pstm.setString(2, u2);
pstm.execute() ;
con.commit() ;
}
catch( Exception e ){
e.printStackTrace() ;
try{
con.rollback() ;
}
catch( Exception ex ){}
throw new Exception( "DB Excetion :"+e.toString() ) ;
}
finally{
try{
con.close() ;
}catch(Exception ex){} ;
}
return true ;
}
public static boolean getTest( )throws Exception {
Connection con = null ;
try{
con = AccessUtil.getConAccess() ;
Statement s = con.createStatement();
con.setAutoCommit(false);
String sql = " select u1,u2 from tbl_test " ;
PreparedStatement pstm = con.prepareStatement( sql ) ;
ResultSet rs = pstm.executeQuery();
while(rs.next()){
JOptionPane.showMessageDialog(null, rs.getString("u1")+"--"+ rs.getString("u2"));
}
}
catch( Exception e ){
e.printStackTrace() ;
try{
con.rollback() ;
}
catch( Exception ex ){}
throw new Exception( "DB Excetion :"+e.toString() ) ;
}
finally{
try{
con.close() ;
}catch(Exception ex){} ;
}
return true ;
}
}
|
|
|
|
|
|
sharkbc wrote: But i could insert or get correctly UTF8 string ?
The Sun jdbc-odbc bridge does not support UTF-16 which is how MS Access 2003 does unicode.
Possible solutions
- Find a commercial jdbc-odbc bridge that supports it
- Find the commercial MS Access jdbc driver. Far as I know there is only one that does direct versus ODBC implementation.
- Use a different database.
- Encode the data in the database. That of course means it would not be viewable in anything except the java application.
Following bug documents this.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6345277[^]
|
|
|
|
|
|
like this[^]
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
|
Please read the guidelines at the top of this page. Format your message so that it is readable; what you have posted here is far too difficult to read through. You also need to identify which part of your code is failing and what you expect should be happening at that point.
It's time for a new signature.
|
|
|
|
|
hi
iam making a programe for supermarket and i need jave code to use barcode
if u can help me plz send to my mail
max.passion@windowslive.com
and thanks alot
|
|
|
|
|
Oh, yeah. That's going to happen.
L u n a t i c F r i n g e
|
|
|
|
|
Lots of samples on the web if you could learn to use Google.
It's time for a new signature.
|
|
|
|
|
IDAutomation provides a bar code fonts and samples for using it in Java programs. I have used them on several projects with very good results. Most of the barcodes you use the same way as a normal font. 2D barcodes are more involved but the IDAutomation samples can get you going.
|
|
|
|
|
google it
♫ 99 little bugs in the code,
99 bugs in the code
We fix a bug, compile it again
101 little bugs in the code ♫
|
|
|
|
|
|
Hi am a student interested in developing an data analysis application and offer that as SaaS in cloud...
I Would like to develop it in java platform to enable multi-tenancy and scalability of the application..
Am expecting your kind help and suggestion about this project..
Thank U...
Regards,
Sangita S
|
|
|
|
|
See my answer to the question below; take a look at the information here[^].
It's time for a new signature.
|
|
|
|
|
I am last year diploma enginerring college so i want to make project in java on the based on the sms so can tell me how we can make code in sms plz
|
|
|
|
|
You need to go and do some research first on how to access SMS systems via Java. Take a look here[^] at some of the reference materials and tutorials.
It's time for a new signature.
|
|
|
|
|
you hav to break down, what you need to do, and then search bits and pieces on google, do hardwork of assembling and testing. then its yours!
♫ 99 little bugs in the code,
99 bugs in the code
We fix a bug, compile it again
101 little bugs in the code ♫
|
|
|
|
|
hi...i wish 2 create a registration module using java and access as backend,the scenario is :students from 500 colleges participate in a event tat has 4 activities,which the user chooses..but only 8 per college is allowed ...how to tackle 500 colleges..do i hav to create a separate count for each college?
warm regards...
sam
|
|
|
|
|
That would seem to be the sensible way to do it; otherwis how would you tell when the count for a single college gets to 8?
It's time for a new signature.
|
|
|
|
|
That's a wish, not a programming problem..
♫ 99 little bugs in the code,
99 bugs in the code
We fix a bug, compile it again
101 little bugs in the code ♫
|
|
|
|
|
Hello Friends
I am crating one applet based application.Now I want to run that on another system where jre is not available.So,can I use jre that Installed on my system by copying to another one and How can I use then that copied jre?
Or is there any other way to bundle jre with application so that when I try to run that application on any other system where no jre then this bundled jre get in use to run my application.
In actual I want to run my applet when My jre is at some different location other than installed one.
Any Help will be appreciated.
Thanks & Regards
Yogesh
modified on Friday, July 30, 2010 2:38 AM
|
|
|
|
|
I don't think this is possible. Any java app or applet needs to be able to find the registered JRE on the machine where the app/applet is to be run.
It's time for a new signature.
|
|
|
|
|
Is this an applet or an application?
If it is an application then you can simply include the JRE in a directory along with your application distribution and then run the application from that. The advantage of this is that you know which version of the JRE your application will run against, rather than being at the mercy of whichever random JRE happens to be installed as the default on the target machine. There is no need for any installation process or registration, you can copy the JRE directory and then point your application at this and away you go.
An applet is a different matter. If you want to run the applet from within a browser, then that browser must have a Java plug-in of the correct version installed and enabled. There is no way the applet can do this automatically. Normally, I would expect the browser to prompt the user with a message, something like "A required plug-in is missing for this page". In this case, the JRE does have to be properly installed and registered, and you cannot simply copy it over to the other machine.
|
|
|
|