Unable to set WEEK_OF_YEAR in java.util.Calender

in java.util.Calender unable to set WEEK_OF_YEAR, it takes only the current month for any year
could anyone give a solution

hi there,
try this:
Calendar calendar = Calendar.getInstance();
System.out.println("current week of the year is: " + calendar.get(cal.WEEK_OF_YEAR));
System.out.println(cal.getTime());
calendar.set(cal.WEEK_OF_YEAR, 32);
System.out.println("week of the year is now: " + calendar.get(cal.WEEK_OF_YEAR));
System.out.println(cal.getTime());
hope this helps,
PSChan
Sun Microsystems

Similar Messages

  • Unable to capture messages from java.util.logging

    I have a class called (Caller.java) which invokes a method called foo from another java class(Util.java) using reflection API.Now this method foo logs messages using Java's logger.My requirement is to call foo for 3 times from Caller and capture/redirect the log messages into 3 log files.
    But only the first log file is capturing the log messages(from logger) and other two are not ?
    Plz suggest if I am doing somethin wrong here ?
    Caller.java
    package project2;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintStream;
    import java.lang.reflect.Method;
    public class Caller {
        public Caller() {
        public static void main(String[] args) throws Exception {
            Caller caller = new Caller();
            for (int i = 0 ;i<3 ;i++ )  {
                caller.createLogStream(i);
                System.setOut(caller.getPs());
                System.setErr(caller.getPs());
                /*****************Invoking Util.java*****************************/
                Class clas = Class.forName("project2.Util");
                Method m = clas.getMethod("foo",null);
                Object obj =clas.newInstance();
                m.invoke(obj,null);
        public void createLogStream(int i) throws FileNotFoundException {
            ps = new PrintStream(new File(System.getenv("HOME")+File.separator+"MyLog"+i+".log"));
        public void closeLogStream(){
            ps.close();
            ps = null;
        private PrintStream ps = null;
        public PrintStream getPs() {
            return ps;
    } Util.java
    package project2;
    import java.util.logging.Logger;
    public class Util {
        Logger logger = null;
        public Util() {
            logger = Logger.getLogger(this.getClass().getName());
        public void foo(){
            System.out.println("Hello out stream");
            System.err.println("Hello error stream");
            logger.info("This is an information");
            logger.warning("This is a warning message");
            logger.severe("This is fatal!! ");
    }First Log file MyLog0.log:
    Hello out stream
    Hello error stream
    Feb 16, 2009 7:55:55 PM project2.Util foo
    INFO: This is an information
    Feb 16, 2009 7:55:55 PM project2.Util foo
    WARNING: This is a warning message
    Feb 16, 2009 7:55:55 PM project2.Util foo
    SEVERE: This is fatal!!
    Feb 16, 2009 7:55:55 PM project2.Util foo
    INFO: This is an information
    Feb 16, 2009 7:55:55 PM project2.Util foo
    WARNING: This is a warning message
    Feb 16, 2009 7:55:55 PM project2.Util foo
    SEVERE: This is fatal!!
    Feb 16, 2009 7:55:55 PM project2.Util foo
    INFO: This is an information
    Feb 16, 2009 7:55:55 PM project2.Util foo
    WARNING: This is a warning message
    Feb 16, 2009 7:55:55 PM project2.Util foo
    SEVERE: This is fatal!! Other 2 log files have only this much
    Hello out stream
    Hello error stream

    A stale Connection Factory or Connection Handle may be used in SOA 11g
    Regards,
    Anuj

  • Unable to set Answers from Java Script

    Hi,
    After user selects the answer for a particular question, i am able to get the selected answer using below Java script.
    var cp = document.Captivate;
    alert(cp.cpEIGetValue("m_VarHandle.cpQuizInfoAnswerChoice"));
    Based on some user info, i want to set the default answer using below Java Script. But below statement does not make the answer selection on the question slide.
    var cp = document.Captivate;
    cp.cpEISetValue("m_VarHandle.cpQuizInfoAnswerChoice","A");
    Is there a way we can set answer for a question dynamically using onEnter Action?
    Thanks,
    Krishna

    You first have to instantiate your class:
    DECLARE
      obj   ORA_JAVA.JOBJECT;
    BEGIN
      obj:=CLASSFORMS.new;     
      MESSAGE(CLASSFORMS.SALUDO(obj));
      MESSAGE(' ');
    END;

  • Java.util.logging - Problem with setting different Levels for each Handler

    Hello all,
    I am having issues setting up the java.util.logging system to use multiple handlers.
    I will paste the relevant code below, but basically I have 3 Handlers. One is a custom handler that opens a JOptionPane dialog with the specified error, the others are ConsoleHandler and FileHandler. I want Console and File to display ALL levels, and I want the custom handler to only display SEVERE levels.
    As it is now, all log levels are being displayed in the JOptionPane, and the Console is displaying duplicates.
    Here is the code that sets up the logger:
    logger = Logger.getLogger("lib.srr.applet");
    // I have tried both with and without the following statement          
    logger.setLevel(Level.ALL);
    // Log to file for all levels FINER and up
    FileHandler fh = new FileHandler("mylog.log");
    fh.setFormatter(new SimpleFormatter());
    fh.setLevel(Level.FINER);
    // Log to console for all levels FINER and up
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(Level.FINER);
    // Log SEVERE levels to the User, through a JOptionPane message dialog
    SRRUserAlertHandler uah = new SRRUserAlertHandler();
    uah.setLevel(Level.SEVERE);
    uah.setFormatter(new SRRUserAlertFormatter());
    // Add handlers
    logger.addHandler(fh);
    logger.addHandler(ch);
    logger.addHandler(uah);
    logger.info(fh.getLevel().toString() + " -- " + ch.getLevel().toString() + " -- " + uah.getLevel().toString());
    logger.info("Logger Initialized.");Both of those logger.info() calls displays to the SRRUserAlertHandler, despite the level being set to SEVERE.
    The getLevel calls displays the proper levels: "FINER -- FINER -- SEVERE"
    When I start up the applet, I get the following in the console:
    Apr 28, 2009 12:01:34 PM lib.srr.applet.SRR initLogger
    INFO: FINER -- FINER -- SEVERE
    Apr 28, 2009 12:01:34 PM lib.srr.applet.SRR initLogger
    INFO: FINER -- FINER -- SEVERE
    Apr 28, 2009 12:01:40 PM lib.srr.applet.SRR initLogger
    INFO: Logger Initialized.
    Apr 28, 2009 12:01:40 PM lib.srr.applet.SRR initLogger
    INFO: Logger Initialized.
    Apr 28, 2009 12:01:41 PM lib.srr.applet.SRR init
    INFO: Preparing Helper Files.
    Apr 28, 2009 12:01:41 PM lib.srr.applet.SRR init
    INFO: Preparing Helper Files.
    Apr 28, 2009 12:01:42 PM lib.srr.applet.SRR init
    INFO: Getting PC Name.
    Apr 28, 2009 12:01:42 PM lib.srr.applet.SRR init
    INFO: Getting PC Name.
    Apr 28, 2009 12:01:42 PM lib.srr.applet.SRR init
    INFO: Finished Initialization.
    Apr 28, 2009 12:01:42 PM lib.srr.applet.SRR init
    INFO: Finished Initialization.Notice they all display twice. Each of those are also being displayed to the user through the JOptionPane dialogs.
    Any ideas how I can properly set this up to send ONLY SEVERE to the user, and FINER and up to the File/Console?
    Thanks!
    Edit:
    Just in case, here is the code for my SRRUserAlertHandler:
    public class SRRUserAlertHandler extends Handler {
         public void close() throws SecurityException {
         public void flush() {
         public void publish(LogRecord arg0) {
              JOptionPane.showMessageDialog(null, arg0.getMessage());
    }Edited by: compbry15 on Apr 28, 2009 9:44 AM

    For now I have fixed the issue of setLevel not working by making a Filter class:
    public class SRRUserAlertFilter implements Filter {
         public boolean isLoggable(LogRecord arg0) {
              if (arg0.getLevel().intValue() >= Level.WARNING.intValue()) {
                   System.err.println(arg0.getLevel().intValue() + " -- " + Level.WARNING.intValue());
                   return true;
              return false;
    }My new SRRUserAlertHandler goes like this now:
    public class SRRUserAlertHandler extends Handler {
         public void close() throws SecurityException {
         public void flush() {
         public void publish(LogRecord arg0) {
              Filter theFilter = this.getFilter();
              if (theFilter.isLoggable(arg0))
                   JOptionPane.showMessageDialog(null, arg0.getMessage());
    }This is ugly as sin .. but I cannot be required to change an external config file when this is going in an applet.
    After much searching around, this logging api is quite annoying at times. I have seen numerous other people run into problems with it not logging specific levels, or logging too many levels, etc. A developer should be able to complete configure the system without having to modify external config files.
    Does anyone else have another solution?

  • How can I create an instance of "java.util.prefs.WindowsPreferences"?

    Hi All,
    I was trying to find out a way to access the Windows Registry to add soome keys and and later add a string.
    I found WindowsPreferences might be useful in the above mentioned context.
    I was trying to create an instance of it, but when I import the class, it says it is invisible.
    Can anyone let me know how to instantiate this class.
    Note:- Under the same package "java.util.prefs" we have another class "Preferences", Iam able to import this one and use it in my code.
    Thank You.
    Regards,
    Suman.H

    It's true that Preferences uses the Registry on Windows systems, that does not mean you can use it as a Registry API. The only part of the Registry you can access are those branches that are set aside for java.util.prefs: HKLM\Software\JavaSoft\Prefs and HKCU\Software\JavaSoft\Prefs. IF you need to access other parts of the Registry, you'll need to use JNI or a separate Windows Registry library.

  • Getting compilation error: java.util.Set is an interface. This interface is not supported.

    Hi Folks,
    Is there a limitation in BEA's web services implementation? I have a simple web
    service that returns an array of java objects. However I am calling another middle
    tier API that returns a Set. I convert this Set into array of object and return
    it via the web service.
    However the .jws file that implements the webservice does not compile. I get the
    following error message:
    java.util.Set is an interface. This interface is not supported.
    Is there a limitation on using Collections within the .jws file? If that is the
    case it is a severe limitation.
    Note my Web Service API returns an array of java objects with no collections in
    them.
    Sanjay

    Hello,
    Generic java collections can only be handled in a very generic, weakly
    typed manner.
    Take a look at the
    http://workshop.bea.com/xmlbeans/guide/conXMLBeansSupportBuiltInSchemaTypes.html
    and also
    http://workshop.bea.com/xmlbeans/guide/conJavaTypesGeneratedFromUserDerived.html
    You might also ask your question to the XMLBeans newsgroup:
    http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=xover&group=weblogic.developer.interest.xmlbeans
    Regards,
    Bruce
    Sanjay wrote:
    >
    Hi Folks,
    Is there a limitation in BEA's web services implementation? I have a simple web
    service that returns an array of java objects. However I am calling another middle
    tier API that returns a Set. I convert this Set into array of object and return
    it via the web service.
    However the .jws file that implements the webservice does not compile. I get the
    following error message:
    java.util.Set is an interface. This interface is not supported.
    Is there a limitation on using Collections within the .jws file? If that is the
    case it is a severe limitation.
    Note my Web Service API returns an array of java objects with no collections in
    them.
    Sanjay

  • Puzzled by the redefinition of the methods in java.util.Set

    Hi all,
    I don't understand why those methods in java.util.Set redefined since their counterparts have alrealdy been defined in java.util.Collection and java.util.Set extends java.util.Collection. I agree to redefine boolean add(Object o) because its contract has been modified, but what about the rest like
    size() and iterator() ?
    Thanks.

    Hi all,
    I don't understand why those methods in
    in java.util.Set redefined since their counterparts
    have alrealdy been defined in java.util.Collection
    and java.util.Set extends java.util.Collection. I
    agree to redefine boolean add(Object o) because its
    contract has been modified, but what about the rest
    like
    size() and iterator() ?Completeness's sake?
    ~Cheers

  • How to set property "java.util.Arrays.useLegacyMergeSort" in jnlp-file?

    Hi,
    I have a problem in a web start application with java 7 and the new sort behavior (exception: comparison method violates its general contract).
    So I like to go back to previous behavior and tried to put the new java 7 system property "java.util.Arrays.useLegacyMergeSort" in the generated jnlp-File:
    <property name="java.util.Arrays.useLegacyMergeSort" value="true"/>.
    Now I can read the property value in java code with System.getProperty("java.util.Arrays.useLegacyMergeSort"), and guess the property was successful set, but the exception still appears?!
    The system property works with command line "javaws -J-Djava.util.Arrays.useLegacyMergeSort=true file.jnlp", but not via doubleclick on the jnlp-file or url and browser.
    Any ideas?
    Cheers,
    Dan

    Only "trusted" set of properties can be set in the JNLP file by unsigned applications.
    List of properties is revised from time to time but it usually takes time for new properties to be added to it (if there is strong demand for it as every property should undergo security audit).
    You can specify arbitrary property if you sign your application and JNLP file.

  • Failed to unmarshal interface java.util.Set

    I am trying to get all mbeans using getAllMBeans() method after
    getting MBeanHome successfully. The method fails with the following
    error.
    Any clues ?
    Thanks
    karthik
    >>>>
    weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception -
    with nested exception:
    [java.rmi.UnmarshalException: failed to unmarshal interface
    java.util.Set; nested exception is:
         java.io.InvalidClassException: javax.management.MBeanAttributeInfo;
    local class incompatible: stream classdesc serialVersionUID =
    7043855487133450673, local class serialVersionUID =
    8644704819898565848]
         at weblogic.management.internal.AdminMBeanHomeImpl_WLStub.getAllMBeans(Unknown
    Source)

    I am trying to get all mbeans using getAllMBeans() method after
    getting MBeanHome successfully. The method fails with the following
    error.
    Any clues ?
    Thanks
    karthik
    >>>>
    weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception -
    with nested exception:
    [java.rmi.UnmarshalException: failed to unmarshal interface
    java.util.Set; nested exception is:
         java.io.InvalidClassException: javax.management.MBeanAttributeInfo;
    local class incompatible: stream classdesc serialVersionUID =
    7043855487133450673, local class serialVersionUID =
    8644704819898565848]
         at weblogic.management.internal.AdminMBeanHomeImpl_WLStub.getAllMBeans(Unknown
    Source)

  • Org.exolab.castor.xml.MarshalException:Unable to instantiate java.util.List

    Hi,
    I am using castor to unmarshal an xml into a java object.
    This object has member variables as collections (List).
    Even though in the mapping file I used collections attribute of <field> tag and has set it to arraylist, it is still throwing this exception.
    After doing a bit of research on this,I found that since UnmarshalHandler uses reflection to create object from xml, it is trying to invoke java.util.List.newInstance() which is causing this problem.
    The class which I am trying to unmarshal is an already existing class and I cannot change the type of the member variables to ArrayList from List.
    How can it be resolved?

    The exception trace is as below :
    Caused by: java.lang.InstantiationException: java.util.List() method not
    found
    at
    org.exolab.castor.xml.UnmarshalHandler.createInstance(UnmarshalHandler.java:2584)
    at
    org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:2348)
    at
    org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1436)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
    Source)
    at
    org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
    Source)

  • TestNG with java.util.Set

    hi, i want to test simple method:
    @Parameters({"lista"})
    @Test
    public GroupedFiles groupFiles(Set<File> p_files){
    }and i have definition of my xml:
    <suite name="My suite">
      <parameter name="first-name"  value="Cedric"/>
      <test name="Simple example">
      <-- ... -->and my testNG throws me uknown for me exception:
    java.lang.AssertionError: Unsupported type parameter : interface java.util.Set
    could anyone help me with this case, thanks for any knowledge

    'little code modification'
    hi, i want to test simple method:
    @Parameters({"lista"})
    @Test
    public GroupedFiles groupFiles(Set<File> p_files){
    }and i have definition of my xml:
    <suite name="My suite">
      <parameter name="lista"  value="java.util.Set"/>
      <test name="Simple example">
      <-- ... -->and my testNG throws me uknown for me exception:
    java.lang.AssertionError: Unsupported type parameter : interface java.util.Set
    could anyone help me with this case, thanks for any knowledge

  • ADF Faces af:table support java.util.Set

    I was using a java.util.Set in my model classes, as implementation of the Collection interface. And wanted to show the Set using a <af:table> after a while I discoverded that the documentation did not mention support of java.util.Set, only List.
    Now I have to convert my collection to List in the backing beans of my view.
    Is there a better approch than converting every Set in the view using
    new Arraylist(set)?
    And what is the reason of the missing Set support (or General Colelction support)?
    Thank you

    Deepak, I don't think you know what you're writing about.
    No, we do not support java.util.Set in <af:table>. For that matter, neither does <h:dataTable>.
    The "why" of it is that we require indexed access into the table for operations like "Display rows 526-550". java.util.Set does not offer indexed access.
    By the way, one corollary - do not use java.util.LinkedList with tables (ADF Faces or the JSF data table). If the list is small, then it won't be a problem, but with a large list, you'll get brutal performance.

  • Unable to override the method get(int) in java.util.AbstractList

    package util;
    import java.util.Vector;
    import java.lang.Integer;
    public class integerVector extends Vector
    public integerVector() { //construct a Vector()
    super();
    public integerVector(int m) { // construct a Vector(m)
    super(m);
    public integerVector(int m, int n) { // construct a Vector(m,n)
    super(m,n);
    public void set (int i, int n) {
    Integer ii= new Integer(i) ;
    setElementAt(ii,n);
    when i try compiling this i get the following error:
    integerVector.java:37: get(int) in util.integerVector cannot override get(int) i
    n java.util.AbstractList; attempting to use incompatible return type
    found : java.lang.Integer
    required: java.lang.Object
    public Integer get(int n) {
    It would be very helpful if anyone can provide the solution

    The method's signature is defined by the Interface java.util.List.
    public Object get(int index)
    instead you want to implement
    public Integer get(int index)
    Yes you could write a class with this method, and call it IntegerList or similar.
    However it could not implement the List interface, or extend any of the List classes.
    Instead of extending Vector (or ArrayList) you could delegate to it.
    That way you're not extending the class, and not changing the signature of a method.
    public class IntegerList(){
      private List internalList = new ArrayList();
      public Integer get(int index){
        return (Integer)internalList.get(index);
    }This class would be of limited use though, because you couldn't treat it as a regular list because it hasn't implemented the interface properly.
    The best you could do would be to have it implement the collection interface, which doesn't expose the specific get methods.

  • Unable to validate a java.util.Properties XML based File

    I cannot for the life of me figure out what is wrong with this xml file, but it fails the validation of java.util.Properties and as such won't be parsed in. Help!
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
    <properties version="1.0">
      <entry key="bottleneckServer.address"></entry>
      <entry key="bottleneckServer.port">8206</entry>
      <entry key="bottleneckServer.confirmDelay">10</entry>
      <entry key="bottleneckServer.cleanupDelay">120</entry>
    </properties>Thanks in advance!

    This xml file works perfectly.
    Here is some test code:
            Properties p = new Properties();
            p.loadFromXML(getClass().getClassLoader().getResourceAsStream("someFilePath/someFileName.xml"));
            assert "8206".equals(p.getProperty("bottleneckServer.port")) : "Property 'bottleneckServer.port' != 8206";

  • Java.util.MissingResourceException: Can't find bundl :ERROR plz Help

    hey guys am trying to connect to my data base and view data toa jsp page but i got this error :
    Exception report
    message
    descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: java.util.MissingResourceException: Can't find bundle for base name DataBase, locale en_US
    root cause
    java.util.MissingResourceException: Can't find bundle for base name DataBase, locale en_US
    note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.
    here is the code database _proper
    drivername=oracle.jdbc.driver.OracleDriver
    dataSourceName=jdbc/orcl/WOH
    dsLookupPrefix=WOH.getstring("dslookupprefix");
    user=SYSTEM
    password=SYSTEM
    location=192.168.1.3
    port=1521
    sid=ORCL
    and here is the Dao connection class
    package version.dao;
    import java.util.*;
    //to provide JDBC classes
    import java.sql.*;
    * @author freddy
    public class DAODirect {
    * Insert the type's description here.
    * Creation date: (12/25/2006 12:13:56 PM)
    * @author: Administrator
         private Connection connection = null;
         private Statement statement = null;
         private String driverName =null;// "oracle.jdbc.driver.OracleDriver";//null;
         private String url =null;//"jdbc:oracle:thin:scott/tiger@localhost:1521:ORCL";//null;
         private ResultSet rs = null;
         private String columnNames[];
         private int columnCount;
         private Object[] record;
         * PFSDataBase constructor comment.
         public DAODirect() {
              super();
              ResourceBundle database = ResourceBundle.getBundle("DataBase");
    //1 get the driver name
              driverName = database.getString("drivername");
              String user = database.getString("user");
              String password = database.getString("password");
              String location = database.getString("location");
              String port = database.getString("port");
              String sid = database.getString("sid");
    //String dataSourceName=database.getString("dataSourceName");
    //2- get the Connection url
              url =
                   "jdbc:oracle:thin:"
                        + user
                        + "/"
                        + password
                        + "@"
                        + location
                        + ":"
                        + port
                        + ":"
                        + sid;
              System.out.println("++++++++"+url);
    System.out.println("++++++++"+url);
         public void closeStatement() {
              try {
                   if (statement != null) {
                        statement.close();
                        statement = null;
              } catch (Exception e) {
         public void commitDB() throws Exception{
              connection.commit();     
         public boolean connect() throws Exception {
              try {
                   if (connection == null) {
    //1- loading of JDBC Drivers
                        Class.forName(driverName);
                        System.out.println(url);
    //this line =conn = DriverManager.getConnection(
    // "jdbc:oracle:thin:@noizmaker:1521:osiris",
    // "scott", "tiger");
    //2- Establish Connection
                        connection = DriverManager.getConnection(url);
                        return true;
                   } else {
                        throw (
                             new Exception("connection is not disconnected, you have to disconnect this connection before reconnecting it again"));
              } catch (SQLException e) {
                   e.printStackTrace();
                   throw (new Exception("Unable to connect to database,Error Loading Driver"));
         public void createStatement() throws Exception {
              if (statement != null) {
                   closeStatement();
              if (connection == null) {
                   throw (new Exception("database is not connected"));
              statement = connection.createStatement();//3-bulit_in funnction that create and send sql statment
         public void disconnect() throws Exception {
              if (connection != null) {
                   try {
                        connection.close();
                        connection = null;
                   } catch (Exception e) {
                   //isConnected = false;
              } else {
                   throw (new Exception("can not disconnect database"));
    // ResultSet is: A table of data representing a database result set, which is usually generated by executing a statement that queries the database
         public ResultSet execute(String query) throws Exception {
              if (connection == null) {
                   throw (new Exception("database is not connected"));
              if (statement == null) {
                   throw (new Exception("statement is not created"));
              return statement.executeQuery(query);//bulit_in funnction that 4-execute given sql statment
         public void getColumnNames(ResultSet result) throws Exception {
              try {
    //An object that can be used to get information about the types and properties of the columns in a ResultSet object.
                   ResultSetMetaData resultsMetaData = result.getMetaData();
                   columnCount = resultsMetaData.getColumnCount();
                   columnNames = new String[columnCount];
                   for (int i = 1; i < columnCount + 1; i++) {
                        columnNames[i - 1] = resultsMetaData.getColumnName(i).trim();//trim to remove whaite space
              } catch (Exception e) {
                   throw (new Exception("Result Set Columns " + e.getMessage()));
         public Connection getConnection(){
              return connection;     
         public void rollBack() throws Exception{
              connection.rollback();     
         public Vector rsToVector(ResultSet rs) throws Exception {
              getColumnNames(rs);
              Vector resultSetData = new Vector();
              resultSetData.addElement(columnNames);
              try {
                   this.record = new Object[columnCount];
                   while (rs.next()) {
    //ave each raw
                        Object[] record = new Object[columnCount];
                        for (int i = 1; i < columnCount + 1; i++) {
                             Object entry = rs.getObject(i);
                             record[i - 1] = entry;
    // here we print the whole tabel after we save each record in record[]
                        resultSetData.addElement(record);
                   return resultSetData;
              } catch (Exception e) {
                   resultSetData.clear();
                   throw (new Exception("Result Set : " + e.getMessage()));
         public void setAutoCommit(boolean commitType) throws Exception{
              connection.setAutoCommit(commitType);     
         public boolean update(String query) throws Exception {
              if (connection == null) {
                   throw (new Exception("database is not connected"));
              try {
    //create query and execute it
                   createStatement();
                   statement.execute(query);
                   return true;
              } catch (Exception e) {
                   throw (
                        new Exception(
                             "Error in manipulating query :" + e.getMessage()));
              } finally {
                   closeStatement();
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package version.dao;
    import java.sql.ResultSet;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.SQLException;
    import javax.sql.DataSource;
    import javax.naming.InitialContext;//unknown
    import java.util.ResourceBundle;//unknown
    * @author freddy
    * This is the Data Access Object (DAO), which deals with all Database transactions,
    * connections,and pooling (through Data Source implementation).
    * This class configured through the database.properties file
    * which contains all the database parameters
    * @author: Tariq Qasem
    public class DAO {
         private Connection connection = null;
         private Statement statement = null;
         private String dataSourceName =null; //MyDataSource; //null;
         private String dsLookupPrefix = null;//java:comp/env/;
    //null;
         private ResultSet rs = null;
         * DAO constructor comment.
         public DAO() {
              super();
              ResourceBundle database = ResourceBundle.getBundle("DataBase");
              dataSourceName = database.getString("dataSourceName");
              dsLookupPrefix = database.getString("dsLookupPrefix");
         * @param request PortletRequest
         * @return void
         * this method close pooled statement
         public void closeStatement() {
              try {
                   if (statement != null) {
                        statement.close();
                        statement = null;
              } catch (Exception e) {
         * @param request PortletRequest
         * @return boolean
         * this method connects to the database
         public boolean connect() throws Exception {
              try {
                   if (connection == null) {
                        InitialContext ctx = new InitialContext();
                   DataSource ds = (DataSource) ctx.lookup(dsLookupPrefix+dataSourceName);
                        connection = ds.getConnection();
                        return true;
                   } else {
                        throw (
                             new Exception("connection is not disconnected, you have to disconnect this connection before reconnecting it again"));
              } catch (SQLException e) {
                   e.printStackTrace();
                   throw (new Exception("Unable to connect to database"));
         public void createStatement() throws Exception {
              if (statement != null) {
                   closeStatement();
              if (connection == null) {
                   throw (new Exception("database is not connected"));
              statement = connection.createStatement();
         * @param request PortletRequest
         * @return void
         * this method disconnect the database connection
         public void disconnect() throws Exception {
              if (connection != null) {
                   try {
                        connection.close();
                        connection = null;
                   } catch (Exception e) {
              } else {
                   throw (new Exception("can not disconnect database"));
         * @param request PortletRequest
         * @return boolean
         * this method updates (executes) Insert and Updates queries on the database
    /*     public boolean update(String query) throws Exception {
              if (connection == null) {
                   throw (new Exception("database is not connected"));
              try {
                   createStatement();
                   statement.execute(query);
                   return true;
              } catch (Exception e) {
                   throw (
                        new Exception(
                             "Error in manipulating query :" + e.getMessage()));
              } finally {
                   closeStatement();
         public int update(String query) throws Exception {
              int records = 0;
              if (connection == null) {
                   throw (new Exception("database is not connected"));
              try {
                   createStatement();
                   records = statement.executeUpdate(query);
                   return records;
              } catch (Exception e) {
                   throw (
                        new Exception(
                             "Error in manipulating query :" + e.getMessage()));
              } finally {
                   closeStatement();
         * @param request PortletRequest
         * @return ResultSet
         * this method executes select queries on the database
         public ResultSet execute(String query) throws Exception {
              if (connection == null) {
                   throw (new Exception("database is not connected"));
              if (statement == null) {
                   throw (new Exception("statement is not created"));
              return statement.executeQuery(query);
         * @param request PortletRequest
         * @return void
         * this method to set the commit transaction on the database to be auto
         public void setAutoCommit(boolean commitType) throws Exception{
              connection.setAutoCommit(commitType);     
         * @param request PortletRequest
         * @return void
         * this method commit database transaction
         public void commitDB() throws Exception{
              connection.commit();     
         * @param request PortletRequest
         * @return void
         * this method rollback database transaction
         public void rollBack() throws Exception{
              connection.rollback();     
         * @param request PortletRequest
         * @return Connection
         * this method return the database connection as java object
         public Connection getConnection(){
              return connection;     
    and this is my jsp page:
    <%--
    Document : index
    Created on : Mar 16, 2008, 10:14:55 AM
    Author : freddy
    --%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h2>Hello World!</h2>
    <%
    version.dao.DAODirect dao=new version.dao.DAODirect();
    try
    boolean connected = dao.connect();
    dao.createStatement();
    String query = " SELECT ID,NAME FROM version";
    java.sql.ResultSet rs = dao.execute(query);
    while(rs.next()){
    out.println(rs.getInt("P_ID")+" ");
    out.println(rs.getString("P_FN")+"<BR>");
    dao.closeStatement();
    dao.disconnect();
    catch(Exception e)
    out.print(e.getMessage());
    %>
    </body>
    </html>
    plz guys help me i need this for my graduation project also if anyone know kind of tutorialsfor building J2me/J2EE application using wifi plzzzsend me links or anything ,thx in advance

    This can happen after modifying the calendar properties and not reloading the application. Try reloading or restarting the application. This could also mean the Calendar.properties file has been moved, deleted, or become corrupted. A default properties file can be found at:
    "Tomcat-install-dir"\webapps\"your-web-application"\WEB-INF\classes\defaultPropFile\. Copy this file to: "Tomcat-install-dir"\webapps\"your-web-application"\WEB-INF\classes\. Stop and restart the web server. From a browser, run "hostname"/"your-web-application"/src/setupCalendar.jsp.

Maybe you are looking for

  • Creation of classification view in mm01

    Hi Friends, I want to create classification view for Tran: mm01 , What bapi should iused. Thanks, Asha

  • Excel Output Wrapping columns Xml Publisher

    Hi, I am creating a RTF Template in XML Publisher, Need some help regarding the Output Format Excel:- When I am generating the excel output everything looks ok except the one i.e. data in some columns is automatically wrapping up and I need Data shou

  • MacOS, Bootcamp, Win-Antivirus and (...User symlinks?)

    Hi, I'd appreciate some command line help on this issue: My setup: 750GB HDD with MacOS, apps, and Admin account, and Bootcamp partition; 2 1TB HDDs RAIDed 0 for 2 User accounts; Bootcamp: Win XP SP3, McAfee Security, MacDrive (enabling access to Mac

  • Fireworks CS4 PC version won't recognize my .ase file.

    I can download my kuler swatches as an .ase file without problems. But when I go to Fireworks, I can't load the file into the Swatches palette. I tried "Add swatches" and "Replace swatches" in Fireworks, but Fireworks will only allow me to look for a

  • Stop sign on port type definition in orchestration view

    I'm trying to debug an issue with a custom error class thrown from a wcf service. In my orchestration the port type has what looks like an error indicator: What does the small stop sign mean? Is this an error indicator from visual studio or an indica