Why string has an extra blank when I use EJB business method to get it

I have the following code:
Person bean = home.create("Jon", 10, "Huge", 1.0);
java.util.Enumeration result = home.findAll();
if (result.hasMoreElements()) {
Person bean1 =(Person) javax.rmi.PortableRemoteObject.narrow(result.nextElement(), Person.class);
getTraceWriter().println(" ** name = " + bean1.getName() + ", rank = " + bean1.getRank() +
", power = " + bean1.getPower() + ", rating = " + bean1.getRating());
bean1.remove();
I found the bean1.getName is "Jon " instead of "Jon". why???? Does sb. have a clue?
Thanks,
JST

Here is the code. Thanks very much!
import javax.ejb.*;
import java.sql.*;
import javax.sql.DataSource;
import java.util.Vector;
import java.util.Enumeration;
import javax.naming.Context;
public class PersonBean implements EntityBean {
public String name;
public int rank;
public String power;
public double rating;
public EntityContext context;
private DataSource ds = null;
private String user = "db2admin";
private String password = "db2admin";
* ejbCreate method
* @param name String The person name
* @exception javax.ejb.CreateException
public PersonKey ejbCreate(String name)
throws CreateException {
return ejbCreate(name, 0, "default", 0.0);
* ejbCreate method
* @param name String The person name
* @param rank int The person rank
* @param power String The person power
* @param rating double Rating of the person
* @exception javax.ejb.CreateException
public PersonKey ejbCreate(String name, int rank, String power, double rating)
throws CreateException {
if (name == null || name.length() == 0) {
throw new CreateException("Invalid parameter: name cannot be null");
else if (power == null || power.length() == 0) {
throw new CreateException("Invalid parameter: power cannot be null");
this.name = name;
this.rank = rank;
this.power = power;
this.rating = rating;
Connection con = null;
PreparedStatement ps = null;
try {
System.err.println("before getconnection");
con = this.getConnection();
System.err.println("after getconnection");
ps = con.prepareStatement("insert into TESTMEN values (?,?,?,?)");
ps.setString(1, name);
ps.setInt(2, rank);
ps.setString(3, power);
ps.setDouble(4, rating);
if (ps.executeUpdate() != 1) {
throw new CreateException("Failed to add (" + name + "," + rank + "," +
power + "," + rating + ") to database.");
PersonKey pk = new PersonKey(name);
return pk;
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
public void ejbPostCreate(String name, int rank, String power, double rating) {
// empty for now
public void ejbPostCreate(String name) {
// empty for now
* ejbFindPrimaryKey
* Find bean by primary key
* @return PersonKey Primary key object for the bean
* @exception FinderException
* @exception ObjectNotFoundException
public PersonKey ejbFindByPrimaryKey(PersonKey key)
throws FinderException, ObjectNotFoundException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
boolean found = false;
boolean multipleFound = false;
try {
con = this.getConnection();
ps = con.prepareStatement("select name from TESTMEN where name = ?");
ps.setString(1, key.name);
rs = ps.executeQuery();
found = rs.next();
if (found) {
multipleFound = rs.next();
if (!multipleFound) {
return key;
else {
throw new FinderException("Multiple objects found with name = " + name);
else {
throw new ObjectNotFoundException("Cannot find object with name = " + name);
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (rs != null) rs.close();
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
* setEntityContext method
public void setEntityContext(EntityContext context) {
this.context = context;
* unsetEntityContext method
public void unsetEntityContext() {
context = null;
* ejbFindAll method
* Find all the beans.
* @return java.util.Enumeration Enumeration of all beans
public Enumeration ejbFindAll(){
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = this.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery("select * from TESTMEN");
Vector keys = new Vector();
while (rs.next()) {
keys.addElement(new PersonKey(rs.getString("name")));
return keys.elements();
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
* ejbActivate() method
public void ejbActivate() {}
* ejbPassivate method
public void ejbPassivate() {}
* ejbLoad method
public void ejbLoad() {
PersonKey pk = (PersonKey) context.getPrimaryKey();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = this.getConnection();
ps = con.prepareStatement("select * from TESTMEN where name = ?");
ps.setString(1, pk.name);
rs = ps.executeQuery();
if (rs.next()) {
name = pk.name;
rank = rs.getInt("rank");
power = rs.getString("power");
rating = rs.getDouble("rating");
else {
throw new EJBException("No record found in ejbLoad()");
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (rs != null) rs.close();
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
* ejbStore method
public void ejbStore() {
Connection con = null;
PreparedStatement ps = null;
try {
con = this.getConnection();
ps = con.prepareStatement("update TESTMEN set " +
"name = ?, rank = ?, power =?, rating = ? where name = ?");
ps.setString(1, name);
ps.setInt(2, rank);
ps.setString(3, power);
ps.setDouble(4, rating);
ps.setString(5, name);
if (ps.executeUpdate() != 1) {
throw new EJBException("Failed in updating database in ejbSotre().");
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();
* ejbRemove method
public void ejbRemove() {
Connection con = null;
PreparedStatement ps = null;
try {
con = this.getConnection();
ps = con.prepareStatement("delete from TESTMEN where name = ?");
ps.setString(1, name);
if (ps.executeUpdate() != 1) {
throw new EJBException("cannot remove by name = " + name);
catch (javax.naming.NamingException ne) {
throw new EJBException (ne);
catch (SQLException sqle) {
throw new EJBException(sqle);
finally {
try {
if (ps != null) ps.close();
if (con != null) con.close();
catch (SQLException sqle) {
sqle.printStackTrace();

Similar Messages

  • Why is the word count different when I use word count from the tools menu to the number at the bottom of my mac word document

    Why is the word count different when I use word count from the tools menu to the number at the bottom of my mac word document

    This forum is for Apple's defunct office suite 'AppleWorks' - since the word count is not in the places you mention I assume you are talking about Microsoft Word? Though it's just possible someone in this forum might also use Word and know the answer, you would stand a higher chance of getting an answer in Microsoft's own forums. You could also try asking in the forum applicable to your operating system - Lion, Mavericks or whatever - on the reasonably chance of finding someone familiar with Word.

  • I have a MacBook running a 10.7.5 OS.  Of late it has started hanging, especially when I use Safari.  Can anyone help?

    I have a MacBook that's four years old, runs on iOSX 10.7.5 but of late has been hanging, especially when I use Safari.  Can anyone help?

    Carolyn,
    I searched my whole system and couldn't find
    com.apple.systemuiser.plist
    So that is a mystery.  However the part about:
    Go back to System Preferences > Network
    Make sure the box is selected next to:  Show Wi-Fi status i menu bar. Solved the problem.  Somehow the box had been unchecked.  Gremlins I guess!
    Thanks so much for your help.
    L.

  • Why my old emails show up when I use the spotlight search?

    why my deleted emails show up when I use the Spotlight search?

    Hi ..
    Try a reset.
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    If that doesn't help, tap Settings > General > Reset > Reset All Settings
    No data is lost due to a reset.

  • Why won't my ipod charge when i use my new usb

    why won't my ipod charge when i use my new usb is used?

    A new USB what? Cable? If the old one still works and the new one does not that would point to a bad new cable.

  • I recently upgraded my internet service with Comcast for faster internet.  When I user ethernet connection I get 50 MB download speed....when I use the wireless connection I get 10-20 MB speed.  I have an airport extreme...3-4 years old.  Why?

    I recently upgraded my internet service with Comcast for faster internet.  When I use an ethernet connection I get 50 MB download speed....when I use the wireless connection I get 10-20 MB speed.  I have an airport extreme...3-4 years old.  Why is the speed so different and are there settings I can change to increase the wireless speed?

    If your supposed to be getting 20 Mb/s down via your ISP and both Mac's are not getting that on the SpeedTest, then obviously your router appears to be the cause.
    Connect one Mac directly to the ISP's modem, power off/wait 30 seconds/then power on, then power on the Mac. The ISP will connect directly to the Mac, then run a SpeedTest.
    Then repeat the same for the other Mac. If both Mac's have a problem then it's possibly the ISP, the modem, your lines to them or on your property, or both Mac's are messed up.
    You'll have to keep searching for the cause. Call your ISP and ask then to run a test to see if your getting your 20 Mb/s to your modem, that should clear part of the problem.
    Diagnosing network issues

  • Please help me!!!! my macbook pro 15 running on mountain lion is hanging a lot...sometimes when i use any app than it get freeze for some seconds...what should i do?

    please help me!!!! my macbook pro 15 running on mountain lion is hanging a lot...sometimes when i use any app than it get freeze for some seconds...what should i do?

    Hardware Information:
              MacBook Pro - model: MacBookPro8,2
              1 2.2 GHz Intel Core i7 CPU: 4 cores
              4 GB RAM
    System Software:
              OS X 10.8.2 (12C60) - Uptime: 0 days 1:17
    Disk Information:
              TOSHIBA MK5065GSXF disk0 : (500.11 GB)
                        disk0s1 (disk0s1) <not mounted>: 209.7 MB
                        Macintosh HD (disk0s2) /: 499.25 GB (424.92 GB free)
                        Recovery HD (disk0s3) <not mounted>: 650 MB
              HL-DT-ST DVDRW  GS31N 
    USB Information:
              Apple Inc. BRCM2070 Hub
                        Apple Inc. Bluetooth USB Host Controller
              Apple Inc. Apple Internal Keyboard / Trackpad
              Apple Inc. FaceTime HD Camera (Built-in)
              Apple Computer, Inc. IR Receiver
    FireWire Information:
    Kernel Extensions:
    Problem System Launch Daemons:
                     [failed] com.apple.coresymbolicationd.plist
    Problem System Launch Agents:
                     [failed] com.apple.afpstat.plist
                     [failed] com.apple.AirPlayUIAgent.plist
                     [failed] com.apple.coreservices.appleid.authentication.plist
                     [failed] com.apple.rcd.plist
    Launch Daemons:
                     [loaded] com.adobe.fpsaud.plist
                     [loaded] com.adobe.SwitchBoard.plist
                     [loaded] com.google.keystone.daemon.plist
                     [loaded] com.microsoft.office.licensing.helper.plist
    Launch Agents:
                     [loaded] com.adobe.CS5ServiceManager.plist
                     [loaded] com.google.keystone.agent.plist
    User Launch Agents:
                     [loaded] com.adobe.ARM.202f4087f2bbde52e3ac2df389f53a4f123223c9cc56a8fd83a6f7ae.plist
                     [loaded] com.facebook.videochat.Akshay.plist
                     [loaded] com.microsoft.LaunchAgent.SyncServicesAgent.plist
    User Login Items:
              Sony Ericsson Bridge Helper
              BitTorrent
              uTorrent
    3rd Party Preference Panes:
              Flash Player
              Java
    Internet Plug-ins:
              AdobePDFViewer.plugin
              AdobePDFViewerNPAPI.plugin
              Flash Player.plugin
              FlashPlayer-10.6.plugin
              googletalkbrowserplugin.plugin
              JavaAppletPlugin.plugin
              npgtpo3dautoplugin.plugin
              QuickTime Plugin.plugin
              SharePointBrowserPlugin.plugin
    User Internet Plug-ins:
              Google Earth Web Plug-in.plugin
              Picasa.plugin
    Bad Fonts:
              None
    Top Processes:
              14.6  %          WindowServer
              6.9   %          coreaudiod
              6.4   %          uTorrent
              1.9   %          WebProcess
              1.4   %          iTunes
              1.2   %          EtreCheck
              0.5   %          fontd
              0.2   %          NotificationCenter
              0.1   %          Dock
              0.0   %          Microsoft

  • I have locked my iPhone 5 and forgot my password . Phone is disabled and is saying connect to iTunes ! I have tried but never did I synced my phone to any computer but when installed used iCloud how do I get it back on???

    I have locked my iPhone 5 and forgot my password . Phone is disabled and is saying connect to iTunes ! I have tried but never did I synced my phone to any computer but when installed used iCloud how do I get it back on???

    See here
    http://support.apple.com/kb/HT1212

  • When not using EJBs can I make BD a Singleton and cache facade instances?

    Hi,
    In an application which does not use EJBs can I make BD(Business Delegate) a singleton?
    I was very sure about doing this but when I tried Google on the same subject the answers were'nt supportive of this but that was in the context of applications which used EJBs. And also item 4 in Effective Java isnt very supportive of caching Objects at the drop of a hat.
    When not using EJBs would it be an unnecessary thing to make BD a singleton and cahce Facade instances in a BD and DAO instances in a Facade? I am planning to use a array based blocking bounded buffer for the purposes of caching. Or would it be better to make both BD and a facade as SIngletons and just cache DAOs in a Facade?
    Any suggestion would be of good help to me.
    Thanks a lot.

    Not sure I understand all your design, but you seem
    to describe an architecture where requests are queued
    and handled serially.Sorry if I messed up while explaining it. No, it will not be handled serially. Since the BD is a singleton multiple threads can pass messages to it simulteanously, a bit like an object of the Action class in Struts. Since I dont see having any synchronized methods in a BD requests will be handled simulteanously.
    The impact on throughput of handling requests
    serially (as opposed to parallelizing them) probably
    outweights by far the cost of instantiating one more
    object per request...Yes, I understand that but as I explained above the reqests wont be handled serially.
    To be more clear, I am thinking of using any one of these two things:
    1) BD(Singleton)-->Facade(Singleton, caches DAOs in a thread safe data structure)
    2)1) BD(Singleton, caches Facade instances in a thread safe data structure)-->Facade(caches DAOs in a thread safe data structure).
    the thread safe data structure I am planning to have is a array based bounded buffer which blocks using wait and notify mechanism.
    Thank you for the reply.

  • JEditorPane extra blank when display "image inside table"

    Hi,
    I try to use the JEditorPane to view the html file. Everythings work fine except
    shows the following
    <table border="1">
    <tr><td><img src="http://somewhere/a.jpg"></td></tr>
    <tr><td><img src="http://somewhere/b.jpg"></td></tr>
    </table>It can shows out the image inside the table cell.
    But there is an "extra blank line" follow the images. This "extra blank line" is inside the table cell.
    It likes following
    [image]
    [image]
    But it supposes to be like this
    [image]
    [image]
    I try some sample code in web. It also shows the same problem. Any one have ideas and solutions?
    Thanks a lot.
    kfchu

    Worked fine for me. Here is my test program:
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    public class EditorPaneLoad extends JFrame
         public EditorPaneLoad()
              throws Exception
              FileReader reader = new FileReader("blank.html");
              JEditorPane editor = new JEditorPane();
              editor.setContentType( "text/html" );
    //          editor.setEditable( false );
              editor.read(reader, null);
              JScrollPane scrollPane = new JScrollPane( editor );
              scrollPane.setPreferredSize( new Dimension(300, 200) );
              getContentPane().add( scrollPane );
         public static void main(String[] args)
              throws Exception
              EditorPaneLoad frame = new EditorPaneLoad();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • TS3274 My iPad screen has gone dark, but when I use internet it goes light please advise

    My iPad screen as gone. Funny greeny colour, everything including pictures are that colour, but when I use the internet it is normal. Please could you help. I've rebooted but no change

    Some folks here have reported that giving the back of the iPad a couple of sharp whacks has solved this issue - but you do this at your own risk. Best of luck.

  • Why doesn't Firefox close tabs when I use the command-w shortcut keys?

    Every so often, on random sites, I would have 2 or three tabs open. I would command-w (on a Mac) to close the front most tab, and it would close. Bringing the next tab to the front. But when I hit command-w again, I get the warning sound on my Mac, and the tab does not want to close. Even though Firefox is at the most front of applications, and the tab I'm trying to close is at the front of Firefox browser window. I have to click on the page (even though it's already at the front), for command-w to work and close the tab. I've reset Firefox to default twice already. I've even deleted it, and reinstalled it.

    One situation in which Command+w or Ctrl+w might not work is if the "focus" is in a plugin such as the Flash player used on Youtube after you interact with the player controls. Firefox will continue to send the keyboard input to the plugin until you move the focus back to the page. Does that account for any of the problem?

  • Why does my browser go "back" when i use my mousepad

    my browser randomly goes back to the last browser when i use my mousepad.
    == This happened ==
    A few times a week

    thanks Pat. its fully updated.
    Did you go to the mfgr's. Web site, and look at the driver downloads, and then verifying that you have the latest one installed? The reason that I ask is that the OS, and most driver update utilities, will be about 6 mos. out of date, if not more.
    Also, new computers are loaded with a "master" disc, that was probably created at least 6 mos. before it was used to setup your computer, if not a year. The drivers are very old. With a new computer, the first two things that I do are: clean off any "bloatware," that the mfgr. installed, and then update the OS, and ALL drivers. I have seen drivers that are 3 - 4 years old on a new factory build. All good custom builders, will not install bloatware, and will update the OS and all drivers, before delivery. On an assembly line, that will never happen.
    Good luck,
    Hunt

  • Why is my macbook pro overheating when I use iMovie?

    I have a macbook pro with retina display - OS X Version 10.9.2
    I use it on a wooden table, nothing is blocking the fan and it overheats all the time. It's been happening every single time when I use iMovie and the fans start go crazy within two minutes of the application being opened. I am constantly using iMovie (I think it is iMovie 10) for school and this is a recent problem. When this happens I close the application, wait for the fans to return to normal and then open the application again until it happens again. This isn't really a solution I just get worried when the fans start to go crazy so I shut down the application in hopes that it won't happen next time.
    Is this happening to anyone else?
    Thanks

    Hi
    True answer - NO
    Thoughts - YES
    My MBP got 4Gb RAM - and get's a bit hot - 8Gb and it might get cooler - less swapping to Hard Disk
    If Hard Disk is filling up - it also get's hot - I try to keep at least 25Gb free space on Start-Up Hard Disk (external HDs will not help as Mac OS and applications do not utilize space there by automatic - BUT to free up space on Boot HD they are important)
    Running several applications in background e.g. Internet etc - doesn't make my Mac any Cooler - but turning them OFF helps a bit.
    Exchanging the Main Boot Drive to a SSD-Hard Disk also reduces energy use - and speeds things up quit a bit too (not tested by me)
    BTW - When I use Video-CODECS, Photo and Audio file formats - not really easy for iMovie to use - my iMovie also get's full hand task to do. So by converting material first (outside iMovie) the iMovie projects runs so much better.
    Yours Bengt W

  • When I download a movie from iTunes the cover art disappears. I try get info and add the art, it doesn't show up. So it's just gray. It opens and plays fine. Apple can't figure it out. It's an nas drive. When I use a firewire drive I get the art

    When I download movies from iTunes to my NAS drive, I don't get the cover art. It shows up while its downloading, but when it's finish it disappears. If it has an iTunes extra the cover art is there. I tried get info and add the cover art, it never shows. Regardless of how I add it. Funny thing is, if I download the same movie to my external firewire drive, no problem its there. I've called Apple with no success. I've even tried copying the movie with the art from the firewire drive to replace the file on then NAS drive I still loose the movie cover art. I also tried several times to re download it, no luck. Any ideas? I'm out of ideas.

    Do you have any videos/movies in the video app?
    In iTunes if you right click on the video and select Get Info and go to the Option tap what Media Type is shown?

Maybe you are looking for

  • ColdFusion with IIS URL Rewrite - Page never finishes loading

    I am running CF10 on IIS 7.5 with URL Rewrite module installed. All the rewrite rules work perfectly and ColdFusion is returning the correct pages. In order to get the page displayed in the browser I have to manually set the 'content-length' value in

  • ITunes and my Mac don't recognize my iPod Nano (6th generation) under devices?

    iTunes and my Mac don't recognize my iPod Nano (6th generation) under devices? I have tried rebooting/resetting and reinstalling iTunes already. I have also checked the ports and cables, what can be done?

  • Installer exits at start of installation

    Sir, I am installing on computer with following conf. OS: Windows 2000 Pro , Service Pack 3 Norton Internet Security Processor:P4 RAM:1GB Pagefile:2GB When i starts the installation it ask for path , i specify it and choose Enterprise Edition option,

  • Adobe flash issues with both IE6 and Firefox

    I just installed adobe flash 9 on my win2k computer. When I try to go to www.yourminis.com I get two different results, in IE6 I start to get a web page, but then IE freezes. In Firefox, I get a big blue quicktime Q the blinks a bit, then a question

  • How to save ABAP program ?

    Hi all,    How to save Form / SmartForm / program with Screen ? Thanks , Wayne .