Scrolable resultset in windows nt

hi all
I want 2 get a scroalble result set.so i used below code.but i get the "Result Set is Forward Only" error.
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:odbc:exam");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("SELECT Type,QuesText FROM Question");
rs.last();
My database is in sql server2000 & my os is winnt4 server.
any help is appriciated
thanks
gajaba

try it:
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:odbc:exam");
Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=st.executeQuery("SELECT Type,QuesText FROM Question");
rs.last();
By Beck74

Similar Messages

  • Problem with StatelessConnectionPool and Threads on Windows XP

    I am trying to use a StatelessConnectionPool in a multithreaded app under Windows using 10g. The problem is that when my application is exiting and I go to terminate the StatelessConnectionPool, I get an access violation inside Environment::terminateStatlessConnectionPool.
    A short program that demonstrates the problem is at the end of this post. One thing I have noticed is that by calling terminateConnection inside the thread instead of releaseConnection the problem goes away. However, performance really degrades. Thanks in advance.
    #include <windows.h>
    #include <occi.h>
    #include "RegisterDataMappings.h"
    #include "Consumers.h"
    #include "Thread.h"
    using namespace oracle::occi;
    Environment* env = NULL;
    StatelessConnectionPool* connPool = NULL;
    //Derived from opur Thread class
    class TestThread : public Thread
    public:
         TestThread(void){}
    protected:
         //get an object 10 times, sleeping every 500 msecs in between
         virtual DWORD run(void)
              printf("Thread 0x%08x Enter...\n", GetCurrentThreadId());
              Sleep(500);
              int i = 0;
              while(i < 10)
                   try
                        Connection* conn = connPool->getConnection();
                        Statement* stmt = conn->createStatement("select Ref(c) from consumers c where pid = 7038878582");
                        ResultSet* rs = stmt->executeQuery();
                        if(rs->next())
                             Ref<Consumers> consumer = rs->getRef(1);
                             printf("Thread 0x%08x #%d - %.0f\n", GetCurrentThreadId(), i+1, (double)consumer->getconsumerid());
                        stmt->closeResultSet(rs);
                        conn->terminateStatement(stmt);
                        connPool->releaseConnection(conn);
                        //connPool->terminateConnection(conn);
                        Sleep(500);
                        ++i;
                   catch(SQLException& sql)
                        printf("Oracle exception: %s\n", sql.getMessage().c_str());
              printf("Thread 0x%08x Leave...\n", GetCurrentThreadId());
              return 0;
    //Helper function to create a connection
    void createConnection(void)
         env = Environment::createEnvironment((Environment::Mode)(Environment::OBJECT|Environment::THREADED_MUTEXED));
         RegisterDataMappings(env);
         connPool = env->createStatelessConnectionPool("user", "pass", "orcldev", 10, 10, 0, StatelessConnectionPool::HOMOGENEOUS);
    //Helper function to terminate a connection
    void terminateConnection(void)
         env->terminateStatelessConnectionPool(connPool);
         Environment::terminateEnvironment(env);
    int main(int argc, char* argv[])
         try
              //Connect to the database
              createConnection();
              //Create 10 threads and wait for them to complete
              const int numThreads = 10;
              HANDLE handles[numThreads];
              for(int i = 0; i < numThreads; i++)
                   TestThread* thread = new TestThread;
                   thread->start();
                   handles[i] = thread->getThreadHandle();
              WaitForMultipleObjects(numThreads, handles, TRUE, INFINITE);
              //Clean up
              terminateConnection();
         catch(SQLException& sql)
              printf("SQLException caught: %s\n", sql.getMessage().c_str());
         return 0;

    When I search MetaLink for bug 4183098, it says there's nobug 4183098. Any information on this?

  • Need help Take out the null values from the ResultSet and Create a XML file

    hi,
    I wrote something which connects to Database and gets the ResultSet. From that ResultSet I am creating
    a XML file. IN my program these are the main two classes Frame1 and ResultSetToXML. ResultSetToXML which
    takes ResultSet & Boolean value in its constructor. I am passing the ResultSet and Boolean value
    from Frame1 class. I am passing the boolean value to get the null values from the ResultSet and then add those
    null values to XML File. When i run the program it works alright and adds the null and not null values to
    the file. But when i pass the boolean value to take out the null values it would not take it out and adds
    the null and not null values.
    Please look at the code i am posing. I am showing step by step where its not adding the null values.
    Any help is always appreciated.
    Thanks in advance.
    ============================================================================
    Frame1 Class
    ============
    public class Frame1 extends JFrame{
    private JPanel contentPane;
    private XQuery xQuery1 = new XQuery();
    private XYLayout xYLayout1 = new XYLayout();
    public Document doc;
    private JButton jButton2 = new JButton();
    private Connection con;
    private Statement stmt;
    private ResultSetToXML rstx;
    //Construct the frame
    public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    xQuery1.setSql("");
    xQuery1.setUrl("jdbc:odbc:SCANODBC");
    xQuery1.setUserName("SYSDBA");
    xQuery1.setPassword("masterkey");
    xQuery1.setDriver("sun.jdbc.odbc.JdbcOdbcDriver");
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    xQuery1.setSql("Select * from Pinfo where pid=2 or pid=4");
    jButton2.setText("Get XML from DB");
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException ex) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(ex.getMessage());
    try {
    con = DriverManager.getConnection("jdbc:odbc:SCANODBC","SYSDBA", "masterkey");
    stmt = con.createStatement();
    catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton2_actionPerformed(e);
    contentPane.add(jButton2, new XYConstraints(126, 113, -1, -1));
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    void jButton2_actionPerformed(ActionEvent e) {
    try{
    OutputStream out;
    XMLOutputter outputter;
    Element root;
    org.jdom.Document doc;
    root = new Element("PINFO");
    String query = "SELECT * FROM PINFO WHERE PID=2 OR PID=4";
    ResultSet rs = stmt.executeQuery(query);
    /*===========This is where i am passing the ResultSet and boolean=======
    ===========value to either add the null or not null values in the file======*/
    rstx = new ResultSetToXML(rs,true);
    } //end of try
    catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    ======================================================================================
    ResultSetToXML class
    ====================
    public class ResultSetToXML {
    private OutputStream out;
    private Element root;
    private XMLOutputter outputter;
    private Document doc;
    // Constructor
    public ResultSetToXML(ResultSet rs, boolean checkifnull){
    try{
    String tagname="";
    String tagvalue="";
    root = new Element("pinfo");
    while (rs.next()){
    Element users = new Element("Record");
    for(int i=1;i<=rs.getMetaData().getColumnCount(); ++i){
    tagname= rs.getMetaData().getColumnName(i);
    tagvalue=rs.getString(i);
    System.out.println(tagname);
    System.out.println(tagvalue);
    /*============if the boolean value is false it adds the null and not
    null value to the file =====================*/
    /*============else it checks if the value is null or the length is
    less than 0 and does the else clause in the if(checkifnull)===*/
    if(checkifnull){ 
    if((tagvalue == null) || tagvalue.length() < 0 ){
    users.addContent((new Element(tagname).setText(tagvalue)));
    else{
    users.addContent((new Element(tagname).setText(tagvalue)));
    else{
    users.addContent((new Element(tagname).setText(tagvalue)));
    root.addContent(users);
    out=new FileOutputStream("c:/XMLFile.xml");
    doc = new Document(root);
    outputter = new XMLOutputter();
    outputter.output(doc,out);
    catch(IOException ioe){
    System.out.println(ioe);
    catch(SQLException sqle){

    Can someone please help me with this problem
    Thanks.

  • Date based Resultset and Date display

    Hi
    I have two jsp pages. In first page user selects a Date and name, based on that 2nd jsp display a resultset in a table. I want to Display Selected name and Date on 2nd Page. I done it for name and unable to show the Date and query is also to be modified.
    Here is code for my two jsp pages:
    first.jsp
      <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <%@ include file="DataSource.jsp" %>
    <html>
    <head>
    <title>abcd</title>
    <script type="text/javascript" language="javascript">
    function HTML(p){
    if(!p){
    /*default*/
    p='A action align alt B background Base bgcolor BIG BLINK BODY border bordercolor bordercolordark bordercolorlight Br cellpadding cellspacing checked color cols colspan compact content dir DIV enctype face FONT FORM H1 H2 H3 H4 H5 H6 HEAD height Hr href hspace HTML I id Img Input lang language leftmargin LI marginheight marginwidth maxlength Meta method name NOSCRIPT noshade nowrap OL onblur onchange onclick onfocus onload onmouseout onmouseover onreset onselect onsubmit onunload OPTION P PRE profile readonly rows rowspan SCRIPT SELECT size SMALL SPAN src start STRIKE STYLE style SUB SUP TABLE target TD TEXTAREA TH TITLE title topmargin TR TT type U UL valign value vspace width wrap'
    String.prototype.write=function(){
    document.write(this);
    return this
    String.prototype.alert=function(){
    window.alert(this);
    return this
    String.prototype.status=function(){
    window.status=this;
    return this
    var x=[
    function(W){var q=String.fromCharCode(34);return ' x='+q+((typeof(W)!='undefined')?W:'x')+q}/*attr*/,
    function(W){return '<x'+((typeof(W)!='undefined')?W:'')+' />'}/*tag*/,
    function(W){return '<x'+((typeof(W)!='undefined')?W:'')+'>'+this+'</'+'x>'}/*container*/,
    function(W){var o='<x'+((typeof(W)!='undefined')?W:'')+' />';return o+this.join(o)}/*tags*/,
    function(W){var o='<x'+((typeof(W)!='undefined')?W:'')+'>';var c='</'+'x>';return o+this.join(c+o)+c}/*containers*/
    var j=[];
    var f=0;
    var a=p.split(' ');
    var t,u,l;
    for(var i=0;i<a.length;i++){
    t=a;
    u=t.toUpperCase();
    l=t.toLowerCase();
    if(t==l){
    /*attr*/
    j[f]='window.'+u+'='+x[0]
    else if(t==u){
    /*container;containers*/
    j[f]='String.prototype.'+u+'='+x[2]+';Array.prototype.'+u+'='+x[4]
    else{
    /*tag;tags*/
    j[f]='window.'+u+'='+x[1]+';Array.prototype.'+u+'='+x[3]
    /*specific*/
    j[f]=j[f].replace(/x/g,l);
    f++
    window.status='HTML() bookmarklet library: Copyright (c) 2002-'+(new Date()).getFullYear()+', by Richard Edwards. ['+f+' tag/attrs added] ';
    /*implement!*/
    eval(j.join(';'))
    HTML();
    </script>
    <script type="text/javascript" language="javascript">
    function init(){m='January February March April May June July August September October November December'.split(' ');wd='Su M Tu W Th Fr Sa'.split(' ');lom=[31,28,31,30,31,30,31,31,30,31,30,31];sz=25;js='javascript';fn=[function(F){},function(F){DATE=new Date(F.date.value);if(isNaN(DATE.valueOf())){DATE=new Date()};M=DATE.getMonth();D=DATE.getDate();Y=DATE.getFullYear();lom[1]=28;if((Y%/**/4==0)&&((Y%/**/100>0)||(Y%/**/400==0))){lom[1]++}},function(F){if(D>lom[M]){D=lom[M]};F.date.value=(M<9?'0':'')+(1.0+M)+'/'+(D<10?'0':'')+D+'/'+Y;dv.value=F.date.value;if(opener.Page){opener.document.forms[0][dv.name].value=F.date.value}},function(){F=this.form;fn[1](F);M=this.selectedIndex;fn[2](F);fn[0](F)},function(){F=this.form;fn[1](F);D=this.value;fn[2](F);fn[0](F)},function(){F=this.form;fn[1](F);Y=this.value;fn[2](F);fn[0](F)},function(F){fn[1](F);var f=new Date(Y,M,1);var x=1-(f.getDay());for(var i=0;i<49;i++){F.d[i].value=(i<7?wd[i]:'');F.d[i].onclick=this;};for(var i=1;i<=lom[M];i++){w=Math.floor((i-1)/7);n=7+i-x;F.d[n].value=i;F.d[n].onclick=fn[4];if(i==D){F.d[7+i-x].focus()}};for(var i=0;i<F.m.length;i++){F.m[i].selected=(i==M)};F.m.onchange=fn[3];F.y.value=Y;F.y.onchange=fn[5];F.y.onblur=fn[5];fn[2](F)}];fn[0]=fn[6]};init();function popCal(datevalue){if(!datevalue){dv={name:'Today',value:(new Date())}}else{dv=datevalue};var c=ALIGN('center')+HEIGHT(sz);var h=(m.OPTION().SELECT(NAME('m'))+INPUT(TYPE('text')+SIZE(4)+NAME('y'))+INPUT(TYPE('hidden')+NAME('date')+VALUE(dv.value))).TD(COLSPAN(7)+c);var b=INPUT(TYPE('button')+NAME('d')+STYLE('width:'+sz+';height:'+sz)+WIDTH(sz)+c);var r=[b,b,b,b,b,b,b].TD(WIDTH(sz*7)+c);h=[h,r,r,r,r,r,r,r].TR(c).TABLE(BORDER('0')+CELLSPACING('0')+CELLPADDING('0')+c).FORM(NAME('frm')+ACTION(js+'://'));h+=(init+';init();dv=opener.dv;fn[0](document.forms.frm);').SCRIPT(LANGUAGE(js)+TYPE('text/'+js));window.open('','cal'+(new Date()).valueOf(),'height='+sz*9+',width='+sz*8).document.write(h)};
    </script>
    </head>
    <body bgcolor=lightblue>
    <center><h1>xyz</h1></center>
    <hr>
    <br>
    <p>
    <p>
    <p>
    <p>
    <h4>Select a date: </h4>
    <script type="text/javascript" language="javascript">
    (INPUT(NAME("DV")+READONLY())+INPUT(TYPE("button")+VALUE("Calendar..")+ONkLICK("popCal(this.form.DV)"))).FORM().write();
    </script>
    <p>
    <p>
    <br>
    <form method=post action="second.jsp">
    <sql:transaction dataSource="${example}">
         <sql:query var="Power">
              select unique trader_name from exchange_deal where unit_of_measure='mwh'
         </sql:query>
    </sql:transaction>
    <h4><p>Select a Trader:
         <select Name = "TraderDrop">
         <c:forEach var="row" items="${Power.rows}">
    <option size="20"><c:out value="${row.Trader_name}"/></option>
    </c:forEach>
         </select>
    <p>
    </h4>
    <br>
    <input type="submit" value="SUBMIT"/>
    <input type="reset" value="CANCEL"/>
    </form>
    </body>
    </html>
    Second jsp
      <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <%@ include file="DataSource.jsp" %>
    <html>
    <head>
    <title>abc</title>
    </head>
    <body bgcolor=lightblue>
    <center><h1>xyz</h1></center>
    <hr>
    <form name="input" action="pqr.jsp"
    method="get">
    <c:set var="s" value="${param.TraderDrop}" />
    <h3>Trader : <c:out value="${s}" /></h3>
    <c:set var="d" value="${param.date}" />
    <h3>Trade Date: <c:out value="${d}" /></h3>
    <sql:transaction dataSource="${example}">
    <sql:query var="Power">
         SELECT DEAL_ID, DEAL_TYPE, EXCHANGE_NAME, HUB_NAME, ORGINATING_APPLICATION, PRODUCT_ID, TAKER_COMPANY FROM ENYWARE.EXCHANGE_DEAL where TRANSACTION_TIMESTAMP > sysdate - 3 and trader_name = '<c:out value="${s}" />'
    </sql:query>
    </sql:transaction>
    <table border="1">
    <%-- Get the column names for the header of the table --%>
    <tr>
    <c:forEach var="columnName" items="${Power.columnNames}">
    <th><c:out value="${columnName}"/></th>
    </c:forEach>
    </tr>
    <tr>
    <c:forEach var="column" items="${row}">
    <td><c:out value="${column.value}"/></td>
    </c:forEach>
    </tr>
    </c:forEach>
    </table>
    </form>
    </body>
    </html>
    I am using JavaScript calendar for entering date in a Text box.
    Please review code and help me.
    Thanks in Advance
    Surya

    Anitha123 wrote:
    Hi
    Thanks for your reply..
    We execute our application using a batch file which holds the main class file to be executed as below :
    batch file content as below :
    set PATH=.\_jvm\bin
    set JAVA_HOME=.\_jvm
    set CLASSPATH=.\_jvm\lib\rt.jar;.\_jvm\lib\itext.jar
    java -cp %CLASSPATH%;.\classes xx.yy.zz.Ourmainclass
    Here how can i set the time zone as users time zone? we don't use any manifest file for our application..can you please guide me on the same..Very Good...Then here is your answer..
    set PATH=.\_jvm\bin
    set JAVA_HOME=.\_jvm
    set CLASSPATH=.\_jvm\lib\rt.jar;.\_jvm\lib\itext.jar
    java -Duser.timezone=Asia/Calcutta -cp %CLASSPATH%;.\classes xx.yy.zz.OurmainclassIf this will solve your problem.. don't forget to reward duke stars...please..

  • How do I find out the number of rows in a resultset ?

    Without scrolling it.

    And explain to me, oh sarcastic one, how it wouldn't be a better idea to put that data into a datastructure and pass that back.1. Performance with very large ResultSet objects for which only sparse data is desired (that's what pages are for).
    2. Resource optimization.
    3. Efficient sequential processing.
    4. The ability to intelligently determine based on resource usage whether to page the results or use your implementation for small ResultSet objects.
    Answering your points:
    1. I just showed him a very easy way to get the size.
    2. I don't see any advantage of a collection (if that's what you were envisioning) over a paged ResultSet. Actually the ResultSet is a collection of sorts.
    3. Your data is reliant on the connection initially anyway. The collection would only provide an advantage in the possibly short window while the data was being viewed.
    4. You can always resort a ResultSet by requerying.

  • How to extract data from a resultset returned by SQLX query

    Hi all,
    I'm doing a project in which I use SQLX query to extract data and format it into xml from an object-relational database, and return it to a windows application. But when the resultset is returned, I don't know how to extract and display the data from it. The datatype of returned data might be XmlType, but i don't know how to process it..Can anyone help? It's urgent.. Thanks a lot in advance...
    Joanne

    You can use XMLType.extract().

  • Transfer data from a window to another

    Hello All,
    This my first programme,
    In my first window
    I write the name of the company in "INSociete" in the class DataPanelCli when I use the button "findcli" in the class ButtonPanelCli, I'm looking in the tables Cli_fact and Adresse and the request give me the name street of my company BUT
    In my second window
    StruCliBox, I' d like to write again the same informations by transfering the data from the first window to the second... I don't know how I can do it
    Please could you help me here is the code :
    import java.util.*;
    import java.sql.*;
    import java.io.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.awt.Container;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.text.*;
    import java.lang.String;
    public class AppClient extends JFrame {
         private DataPanelCli screenvarcli;
         private JTextArea msgout;
         private Connection dbconn;
         public AppClient() {
              //titre fen�tre
              super( " APPLICATION CLIENT");
              // set up GUI environment
              Container p = getContentPane();
              screenvarcli = new DataPanelCli();
              msgout = new JTextArea( 8, 40);
              p.setLayout( new FlowLayout() );
              p.add( new JScrollPane(screenvarcli) );
              p.add( new JScrollPane(msgout) );
              // DB Connection
              try {
                   String url = "jdbc:odbc:Access";
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   // Cr�ation d'une liaison
                   dbconn = DriverManager.getConnection(url, "dba", "sql" );
                   msgout.append("Connection successful !\n");
              catch (ClassNotFoundException cnfex) {
                   cnfex.printStackTrace();
                   msgout.append("Connection unsuccessful\n" +
                        cnfex.toString());
              catch (SQLException sqlex) {
                   sqlex.printStackTrace();
                   msgout.append("Connection unsuccessful\n" +
                        sqlex.toString());
              catch (Exception excp) {
                   excp.printStackTrace();
                   msgout.append(excp.toString());
              // Complete GUI
              ButtonPanelCli controls = new
              ButtonPanelCli(dbconn, screenvarcli, msgout);
              p.add(controls);
    //          RadioButtons rb = new RadioButtons(dbconn, screenvarcli, msgout);
    //          p.add(rb);
              setSize(500,475);
              show();
         public static void main( String args[]) {
              AppClient cli = new AppClient();
              cli.addWindowListener(
                   new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                             System.exit(0);
    class DataPanelCli extends JPanel {
         JTextField ICCliFact, INSociete,
              ILAdresseA, ICPostal, ILLocalite, ICPays;
         JLabel LCCliFact, LNSociete,
              LLAdresseA, LCPostal, LLLocalite, LCPays;
         public DataPanelCli() {
              //Label Panel
              JPanel labelPanelCli = new JPanel();
              labelPanelCli.setLayout( new GridLayout(6, 1));
              LNSociete = new JLabel( "Nom ", 0);
              labelPanelCli.add(LNSociete);
              LCCliFact = new JLabel( "Num�ro Client", 0);
              labelPanelCli.add(LCCliFact);
              LLAdresseA = new JLabel( "Adresse ", 0);
              labelPanelCli.add(LLAdresseA);
              LCPostal = new JLabel( "Code Postal ", 0);
              labelPanelCli.add(LCPostal);
              LLLocalite = new JLabel( "Localite ", 0);
              labelPanelCli.add(LLLocalite);
              LCPays = new JLabel( "Pays ", 0);
              labelPanelCli.add(LCPays);
              //TextField Panel
              JPanel screenvarcliPanel = new JPanel();
              screenvarcliPanel.setLayout( new GridLayout(6, 1));
              INSociete = new JTextField("Enter Name - click RECHERCHER", 20);
              screenvarcliPanel.add(INSociete);
              ICCliFact = new JTextField( 20);
              screenvarcliPanel.add(ICCliFact);
              ILAdresseA = new JTextField( 20);
              screenvarcliPanel.add(ILAdresseA);
              ICPostal = new JTextField( 20);
              screenvarcliPanel.add(ICPostal);
              ILLocalite = new JTextField( 20);
              screenvarcliPanel.add(ILLocalite);
              ICPays = new JTextField( 20);
              screenvarcliPanel.add(ICPays);
              // Accessibility Section - relate labels and text fields
              // for use by assistive technologies
              LNSociete.setLabelFor( INSociete);
              LLAdresseA.setLabelFor( ILAdresseA);
              LCPostal.setLabelFor( ICPostal);
              LLLocalite.setLabelFor( ILLocalite);
              LCPays.setLabelFor( ICPays);
              setLayout( new GridLayout( 1, 2));
              add( labelPanelCli);
              add( screenvarcliPanel);
    class ButtonPanelCli extends JPanel {
         public ButtonPanelCli( Connection dbc, DataPanelCli scv, JTextArea msg ) {
              setLayout( new GridLayout( 2 ,0 ));
              JButton findcli = new JButton( "Rechercher" );
              findcli.addActionListener( new FindRecCli( dbc, scv, msg ));
              add( findcli );
              JButton addcli = new JButton( "Ajouter" );
              addcli.addActionListener( new AddRecCli( dbc, scv, msg ));
              add( addcli );
              JButton clearcli = new JButton( "Clear" );
              clearcli.addActionListener( new ClearScreenCli( scv ));
              add( clearcli );
              JButton printcli = new JButton( "Impression" );
    //          printcli.addActionListener( new PrintRecCli( dbc, scv, msg ));
              add( printcli );
              JButton structcli = new JButton( "STRUCTURE" );
              structcli.addActionListener( new StructRecCli( dbc, scv, msg ));
              add( structcli );
              JButton commerccli = new JButton( "COMMERCIAL" );
    //          commerccli.addActionListener( new CommercRecCli( dbc, scv, msg ));
              add( commerccli );
              JButton financli = new JButton( "FINANCIER" );
    //          financli.addActionListener( new FinanRecCli( dbc, scv, msg ));
              add( financli );
    class ClearScreenCli implements ActionListener {
         private DataPanelCli screenvarcli;
         public ClearScreenCli( DataPanelCli scv ) {
              screenvarcli = scv;
         public void actionPerformed( ActionEvent e ) {
              screenvarcli.ICCliFact.setText( "" );
              screenvarcli.INSociete.setText( "" );
              screenvarcli.ILAdresseA.setText( "" );
              screenvarcli.ICPostal.setText( "" );
              screenvarcli.ILLocalite.setText( "" );
              screenvarcli.ICPays.setText( "" );
    // Recherche Ajout Maj record
    // FIND NUMERO CLIENT
    class FindRecCli implements ActionListener {
         private DataPanelCli screenvarcli;
         private JTextArea msgout;
         private Connection dbconn;
         public FindRecCli( Connection dbc, DataPanelCli scv, JTextArea msg ) {
              dbconn = dbc;
              screenvarcli = scv;
              msgout = msg;
         public void actionPerformed( ActionEvent e ) {
              try {
                   String rechnom = new String();
                   rechnom = screenvarcli.INSociete.getText();
              if ( !rechnom.equals( "" )) {
                   Statement statement = dbconn.createStatement();
                   String query = "SELECT * " +
                        "FROM Cli_fact, Adresse " +
                        "WHERE Cli_fact.n_societe_c = '" + rechnom + "' " +
                        "AND c_adresse = c_cli_fact " +
                        "AND c_type_adr = '02'";
    //                    "WHERE n_societe_c = '" +
    //                    rechnom + "' ";
                   msgout.append( "\nSending query " +
                   dbconn.nativeSQL( query ) + "\n" );
                   ResultSet rs = statement.executeQuery( query );
                   display( rs );
                   statement.close();
              else
                   screenvarcli.INSociete.setText( "Entrer le NOM de Soci�t� ");
              catch ( SQLException sqlex ) {
                   msgout.append( sqlex.toString() + sqlex.getMessage() );
         // Display results of query
         public void display( ResultSet rs ) {
              try {
                   rs.next();
                   int recordNumber = rs.getInt( 1);
                   if ( recordNumber != 0 ) {
                        screenvarcli.ICCliFact.setText( String.valueOf(recordNumber) );
                        screenvarcli.INSociete.setText( rs.getString(2));
                        screenvarcli.ILAdresseA.setText( rs.getString(35));
                        screenvarcli.ILLocalite.setText( rs.getString(32));
                        screenvarcli.ICPostal.setText( rs.getString(31));
                        screenvarcli.ICPays.setText( rs.getString(33));
                        msgout.append( "\n Enregistrements trouv�s!!!!!!!\n" );
                   else
                        msgout.append( "\nPas d'enregistrements trouv�s\n" );
              catch ( SQLException sqlex ) {
                   msgout.append( "\n*** Nom de Soci�t� pas dans la data Base ***\n" );
    // ADD CLIENT
    class AddRecCli implements ActionListener {
         private DataPanelCli screenvarcli;
         private JTextArea msgout;
         private Connection dbconn;
         public AddRecCli( Connection dbc, DataPanelCli scv, JTextArea msg ) {
              dbconn = dbc;
              screenvarcli = scv;
              msgout = msg;
         public void actionPerformed( ActionEvent e ) {
              try {
              Statement statement = dbconn.createStatement();
              String rechnom = new String();
              rechnom = screenvarcli.INSociete.getText();
              if ( !rechnom.equals( "" )) {
                   String query = "INSERT INTO cli_fact (" +
                   "n_societe_c) VALUES ('" +
                   screenvarcli.INSociete.getText() + "')";
                   msgout.append( "\nSending query " +
                   dbconn.nativeSQL( query ) + "\n" );
                   int result = statement.executeUpdate( query );
                   if ( result == 1 ) {
                   // read just inserted rec to obtain c_cli_fact field
                   // needed to place STRUCTURE COMMERCIAL FINANCIER
                   msgout.append( "\nInsertion r�ussie\n" );
                   try {
                   query = "SELECT * FROM cli_fact WHERE n_societe_c='" +
                        rechnom + "'";
                   ResultSet rs = statement.executeQuery( query );
                   rs.next();
                   screenvarcli.ICCliFact.setText(String.valueOf(rs.getInt(1)));
                   catch ( SQLException sqlex ) {
                   msgout.append( sqlex.toString() );
              else {
                   msgout.append( "\nInsertion NON r�ussie\n" );
                   screenvarcli.INSociete.setText( "" );
              else
              msgout.append( "\nEntrer au moins le non de soci�t� puis press NOUVEAU\n" );
              statement.close();
              catch ( SQLException sqlex ) {
              msgout.append( sqlex.toString() );
              screenvarcli.INSociete.setText("Nom de soci�t� existe d�j� -- reenter");
    // STRUCTURE
    class StructRecCli extends JFrame implements ActionListener {
         private DataPanelCli screenvarcli;
         private JTextArea msgout;
         private Connection dbconn;
         private boolean firsttime = true;
         public StructRecCli( Connection dbc, DataPanelCli scv, JTextArea msg ) {
              super( " APPLICATION CLIENT STUCTURE " );
              dbconn = dbc;
              screenvarcli = scv;
              msgout = msg;
         public void actionPerformed( ActionEvent e) {
              if (firsttime) {
                   Container cnt = getContentPane();
                   cnt.setLayout( new FlowLayout() );
                   StruCliBox ob = new StruCliBox();
                   cnt.add( ob );
         screenvarcli.INSociete.getText();
                   ButtonPanelStr controls = new
                   ButtonPanelStr(dbconn, screenvarcli, msgout);
                   cnt.add(controls);
                   setSize(500, 475);
                   firsttime = false;
              show();
    class StruCliBox extends JPanel {
         JTextField ICCliFact, INSociete,
              ILAdresseA, ICPostal, ILLocalite, ICPays;
         JLabel LCCliFact, LNSociete,
              LLAdresseA, LCPostal, LLLocalite, LCPays;
         public StruCliBox() {
              //Label Panel
              JPanel s = new JPanel();
              s.setLayout( new GridLayout(6, 1));
              LNSociete = new JLabel( "Nom ", 0);
              s.add(LNSociete);
              LCCliFact = new JLabel( "Num�ro Client", 0);
              s.add(LCCliFact);
              LLAdresseA = new JLabel( "Adresse ", 0);
              s.add(LLAdresseA);
              LCPostal = new JLabel( "Code Postal ", 0);
              s.add(LCPostal);
              LLLocalite = new JLabel( "Localite ", 0);
              s.add(LLLocalite);
              LCPays = new JLabel( "Pays ", 0);
              s.add(LCPays);
              //TextField Panel
              JPanel screenvarcliPanel = new JPanel();
              screenvarcliPanel.setLayout( new GridLayout(6, 1));
              INSociete = new JTextField( 20);
              screenvarcliPanel.add(INSociete);
    //          String rechnom = new String();
    //          screenvarcli.INSociete.getText();
              ICCliFact = new JTextField( 20);
              screenvarcliPanel.add(ICCliFact);
              ILAdresseA = new JTextField( 20);
              screenvarcliPanel.add(ILAdresseA);
              ICPostal = new JTextField( 20);
              screenvarcliPanel.add(ICPostal);
              ILLocalite = new JTextField( 20);
              screenvarcliPanel.add(ILLocalite);
              ICPays = new JTextField( 20);
              screenvarcliPanel.add(ICPays);
              // Accessibility Section - relate labels and text fields
              // for use by assistive technologies
    //          LNSociete.setLabelFor( INSociete);
              LLAdresseA.setLabelFor( ILAdresseA);
              LCPostal.setLabelFor( ICPostal);
              LLLocalite.setLabelFor( ILLocalite);
              LCPays.setLabelFor( ICPays);
              setLayout( new GridLayout( 1, 2));
              add( s);
              add( screenvarcliPanel);
    //          setLayout(new FlowLayout() );
    //          add(s);     
    class ButtonPanelStr extends JPanel {
         public ButtonPanelStr( Connection dbc, DataPanelCli scv, JTextArea msg ) {
              setLayout( new GridLayout( 1 ,0 ));
              JButton addstr = new JButton("Ajouter");
    //          addstr.addActionListener( new AddStructure( dbconn, screenvarcli, msgout, ob));
              add( addstr );
              JButton majstr = new JButton("Mise � jour");
    //          majstr.addActionListener( new MajStructure( dbconn, screenvarcli, msgout, ob));
              add( majstr );
              JButton clestr = new JButton("Clear");
    //          clestr.addActionListener( new CleStructure( dbconn, screenvarcli, msgout, ob));
              add( clestr );
              JButton prnstr = new JButton("Impression");
    //          prnstr.addActionListener( new PrnStructure( dbconn, screenvarcli, msgout, ob));
              add( prnstr );

    That means its simply sharing of data between the 2 swing applications.. and if the main application does some updating of the data, the 2nd window will oso be updated?
    Is this what you are trying to say?

  • Adding a window to a container: Error

    Hello there,
    Im facing a problem with my program.My program is about a Car Rental System and I am using GUI for the interface. From the main(CarRental) program,when user click one of the menu, there is another interface will appear for user to enter details.The problem is,my main (CarRental)program is running,click the first menu,then another interface open,but wen user enter details n click buttons , it is not even working. Below is my program:
    //This is main menu program
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import javax.swing.JFrame;
    public class CarRental extends JFrame implements ActionListener{
         JFrame f;
         JLabel l1,l2,l3,choice;
         JPanel p1,p2,p3,p4,p5,p6,p7,p8,p9;
         JButton btnA,btnB,btnC,btnD,btnE,btnF;
         Connection conn;
         Statement stmt;
         ResultSet rs;
         public CarRental(){
              p1=new JPanel();p2=new JPanel();p3=new JPanel();
              p4=new JPanel();p5=new JPanel();p6=new JPanel();
              p7=new JPanel();p8=new JPanel();p9=new JPanel();
              f=new JFrame("New Rental Record");
              l1=new JLabel("........::: Car Rental System :::.........");
              l2=new JLabel("*******************************************************");
              choice=new JLabel("Please select your option:");
              btnA=new JButton("[1] New Rental Record");
              btnB=new JButton("[2] Update Rental Record");
              btnC=new JButton("[3] Search Rental Record");
              btnD=new JButton("[4] Delete Rental Record");
              btnE=new JButton("[5] Display Rental record");
              btnF=new JButton("[6] Exit");
              l3=new JLabel("*******************************************************");
              f.setLayout(new GridLayout(10,1));
              f.pack();
              f.setVisible(true);
              f.setSize(350,500);
              f.setBackground(Color.white);
              p1.add(l1);f.add(p1);
              p2.add(l2);f.add(p2);
              p3.add(choice);f.add(p3);
              p4.add(btnA);f.add(p4);
              p5.add(btnB);f.add(p5);
              p6.add(btnC);f.add(p6);
              p7.add(btnD);f.add(p7);
              p8.add(btnE);f.add(p8);
              p9.add(btnF);f.add(p9);
              btnA.addActionListener(this);
              btnB.addActionListener(this);
              btnC.addActionListener(this);
              btnD.addActionListener(this);
              btnE.addActionListener(this);
              btnF.addActionListener(this);
         f.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent e)
                        {System.exit(0);}});
              public void actionPerformed(ActionEvent e){
                        if(e.getSource()== btnA)
                        {     NewRecord nr=new NewRecord();}
                         else if(e.getSource()== btnB)
                        {     updateRecord ur=new updateRecord();}
                        else if(e.getSource()== btnC)
                        {     searchRecord sr=new searchRecord(); }
                        else if(e.getSource()== btnD)
                        {     deleteRecord dr=new deleteRecord(); }
                        else if(e.getSource()== btnE){
                             try{
                                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                             catch(ClassNotFoundException e3) {
                                  JOptionPane.showMessageDialog(null,"ERROR:"+e3.getMessage());
                             try{
                                  conn=DriverManager.getConnection("Jdbc:Odbc:Car Rental", "", "");
                                  stmt=conn.createStatement();
                                  rs=stmt.executeQuery("Select * from Customer where CustID");
    String s=("CustID:   CustName:    CustAdd:          CustPhone:       No.of days rent:     Rate per rental: \n");
    while(rs.next())
    s=s+rs.getString(1)+"             "+rs.getString(2)+"              "+rs.getString(3)+"              "+rs.getString(4)+"                    "+rs.getString(5)+"                     "+rs.getString(6)+"\n";
                                       JOptionPane.showMessageDialog(null,s);}
    catch(SQLException e4){e4.printStackTrace();}}//end of F
    //to exit the program                    
    else if(e.getSource()== btnF){
    JOptionPane.showMessageDialog(null,"Thank you");System.exit(0);}
    else
    JOptionPane.showMessageDialog(null,"Invalid Option!");System.exit(0);
                   }//end of if statement
    public static void main(String args[]){
              CarRental cr= new CarRental();}//end of main
    }//end of main menu
    //New Rental program when user selects it
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class NewRecord extends JFrame implements ActionListener{
         JFrame f;
         Container c;
         FlowLayout layout;
         JLabel l1,l2,custId,custName,custAdd,custPhone,dayRent,rateRent;
    JTextField tid,tname,tphone,tday,trate;
                                  JTextArea tadd;
                                  JButton save,clear,exit;
                                  Connection conn;
                                  Statement stmt;
                                  ResultSet rs;
                                  JPanel p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11;
                             public NewRecord(){
                                //super("New Record");
                                  layout = new FlowLayout();
                                  c=getContentPane();
                                  c.setLayout(layout);
                                  p1=new JPanel();p2=new JPanel();p3=new JPanel();
                                  p4=new JPanel();p5=new JPanel();p6=new JPanel();
                                  p7=new JPanel();p8=new JPanel();p9=new JPanel();
                                  p10=new JPanel();p11=new JPanel();
                                  f=new JFrame();     
                                  l1=new JLabel("........::: New Rental Record :::.........");
                                  l2=new JLabel("*******************************************************");
                                  custId =new JLabel("Customer ID:");
                                  custName=new JLabel("Customer name:");
                                  custAdd=new JLabel("Customer address:");
                                  custPhone=new JLabel("Customer phone:");
                                  dayRent=new JLabel("Days of rental:");
                                  rateRent=new JLabel("Rate per rental:");
                                  tid= new JTextField(10);
                                  tname=new JTextField(10);
                                  tphone=new JTextField(10);
                                  tadd=new JTextArea(4,30);
                                  tday=new JTextField(5);
                                  trate=new JTextField(10);
                                  save=new JButton("SAVE");
                                  clear=new JButton("CLEAR");
                                  exit=new JButton("EXIT");
                                  f.setLayout(new GridLayout(11,1));
                                  f.setBackground(Color.white);
                                  f.setVisible(true);
                                  f.setSize(600,600);
                                  p1.add(l1);f.add(p1);
                                  p2.add(l2);f.add(p2);
                                  p3.add(custId);p3.add(tid);f.add(p3);     
                                  p4.add(custName);p4.add(tname);f.add(p4);
                                  p5.add(custAdd);p5.add(tadd);f.add(p5);
                                  p6.add(custPhone);p6.add(tphone);f.add(p6);                         
                                  p7.add(dayRent);p7.add(tday);f.add(p7);
                                  p8.add(rateRent);p8.add(trate);f.add(p8);
                                  p9.add(save);f.add(p9);
                                  p10.add(clear);f.add(p10);
                                  p11.add(exit);f.add(p11);
                             /*     f.add(l1);
                                  f.add(l2);
                                  f.add(custId);
                                  f.add(tid);
                                  f.add(custName);
                                  f.add(tname);
                                  f.add(custAdd);
                                  f.add(tadd);
                                  f.add(custPhone);
                                  f.add(tphone);
                                  f.add(dayRent);
                                  f.add(tday);
                                  f.add(rateRent);
                                  f.add(trate);
                                  f.add(save);
                                  f.add(clear);
                                  f.add(exit);*/
                                  c.add(f);
                                  save.addActionListener(this);
                                  clear.addActionListener(this);
                                  exit.addActionListener(this);
                                  f.addWindowListener(new WindowAdapter(){
                                  public void windowClosing(WindowEvent e)
                                       {System.exit(0);}});
                             public void actionPerformed(ActionEvent e){
                                  if(e.getSource()== exit)
                                       {System.exit(0);}
                                  if(e.getSource()== clear){
                                       tid.setText("");
                                       tname.setText("");
                                       tadd.setText("");
                                       tphone.setText("");
                                       tday.setText("");
                                       trate.setText("");}
                                  if(e.getSource()== save){
                                       try{
                                            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                       catch(ClassNotFoundException e1) {
                                            JOptionPane.showMessageDialog(null,"ERROR:"+e1.getMessage());
                                       try{
                                            conn=DriverManager.getConnection("Jdbc:Odbc:Car Rental", "", "");
                                            stmt=conn.createStatement();
                                            rs=stmt.executeQuery("Select * from Customer");
                                            while(rs.next()){
                                            tid.setText(rs.getString(1));
                                            tname.setText(rs.getString(2));
                                            tadd.setText(rs.getString(3));
                                            tphone.setText(rs.getString(4));
                                            tday.setText(rs.getString(5));
                                            trate.setText(rs.getString(6));}
                                            String s=("CustID:   CustName:    CustAdd:          CustPhone:       No.of days rent:     Rate per rental: \n");
                                            while(rs.next())
                                            s=s+rs.getString(1)+"             "+rs.getString(2)+"              "+rs.getString(3)+"              "+rs.getString(4)+"                    "+rs.getString(5)+"                     "+rs.getString(6)+"\n";
                                                 JOptionPane.showMessageDialog(null,s);
                                       catch(SQLException e2){
                                                 e2.printStackTrace();
                             public static void main(String args[]){
                                       NewRecord nr=new NewRecord();
                                  //     nr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                       }//end of newRecord class
                                  }//ends of New rental program
    I tried to use extending to JPanel or JApplet but still the same. Any help??

    Hi,
    In the NewRecord java file, use change the
    f = new JFrame();               
    c = f.getContentPane();, after that all panel add into the container
    p1.add(l1);c.add(p1);                    
    p2.add(l2);c.add(p2);
    p3.add(custId);p3.add(tid);c.add(p3);     
    p4.add(custName);p4.add(tname);c.add(p4);
    p5.add(custAdd);p5.add(tadd);c.add(p5);
    p6.add(custPhone);p6.add(tphone);c.add(p6);          
    p7.add(dayRent);p7.add(tday);c.add(p7);
    p8.add(rateRent);p8.add(trate);c.add(p8);
    p9.add(save);c.add(p9);
    p10.add(clear);c.add(p10);
    p11.add(exit);c.add(p11);and finally remove this line below
    //c.add(f);Try to avoid add frame into the container, or else you will receive adding a window to a container error.
    Rgrds,
    Sen
    Message was edited by:
    arjensen

  • Connecting to MS Access In Windows 7 64-Bit

    Hi.
    As usual, Microsoft has done its best to make this as difficult as possible. The essence of a solution to this problem that I found at http://sushantnayak.wordpress.com/2010/10/25/connect-ms-access-using-jdbc-odbc-in-windows-7-64-bit/ is as follows:
    1. Download and run AccessDatabaseEngine_x64.exe
    (http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16d&displaylang=en)
    2. Change the connection string in your code to:
    Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ= <-db name and path here
    Though the author of the tip had used VB to make the connection, it looked as though the same technique should work with Java. However, I found that the attempted connection kept generating an SQLException. The code that I tried to run is shown below.
    import java.sql.*;
    public class JDBCTest2
    public static void main(String[] args)
    Connection connection = null;
    Statement statement = null;
    ResultSet results = null;
    String fileName = "F:\\Temp\\Finances.mdb";
    I also tried the following (with different fields below):
    String fileName = "F:\\Temp\\ExamResults.accdb";
    String dbString =
    "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="
    + fileName + ";DriverID=22;READONLY=false}";
    //I also tried the above without ';DriverID=22;READONLY=false', but the
    //result was exactly the same.
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    connection = DriverManager.getConnection(dbString, "", "");
    catch (ClassNotFoundException cnfEx)
    System.out.println("* Unable to load driver! *");
    System.exit(1);
    catch (SQLException sqlEx)
    System.out.println("* Cannot connect to database! *");
    //The above message was displayed.
    System.exit(1);
    try
    statement = connection.createStatement();
    results = statement.executeQuery("SELECT * FROM Accounts");
    catch (SQLException sqlEx)
    System.out.println("* Cannot execute query! *");
    System.exit(1);
    try
    while(results.next())
    System.out.println("Account no. " + results.getInt(1));
    System.out.println("Account holder: " + results.getString(3)
    + " " + results.getString(2));
    System.out.printf("Balance: %.2f %n%n",results.getFloat(4));
    catch (SQLException sqlEx)
    System.out.println("* Error retrieving data! *");
    System.exit(1);
    Any help in solving this problem would be most appreciated.
    Thanks.
    Jan ('Yan')

    I believe that my problem may be due to using a 32-bit Access database, rather than a 64-bit one. I am fully aware of how to use c:\windows\syswow64\odbcad32.exe to get round the problem of setting up the required ODBC data source, and that is what I shall be making use of for at least the next year, as I have just been informed that it will be the 32-bit version of MS Access (with Windows 7) that will be used at my institution for the coming academic session. (I lecture at a university.)
    As a consequence of the above, it turns out that I don't really have a problem for the foreseeable future. However, I would like to know (for personal satisfaction, if nothing else) whether the test program would work if it were used with a 64-bit Access database. Unfortunately, it looks as though I won't have the use of a 64-bit version of Access. Consequently, I would be most grateful if anybody out there could try out my test program with 64-bit Access. Obviously, the appropriate database would need to be set up (or an existing one used and the name/path changed accordingly), but the fields wouldn't even have to be set up to match mine. As long as the program gets past the 'Cannot connect to database error message', I'll be happy.
    Thanks.
    Jan

  • HELP! How to save resultset (NOT file) from server databse on local machine

    Our JSP web system allows our clients to be able to search data from the server-side database and then after get the resultset, they also should be able to save these data as a text file on their local machine by just a click. Of course, before they click the OK button, they should navigate the files system on their local machines and choose under which directory they want to put the file, and then provide a file name. I could NOT find a way to be able to navigate the local machine's drives.
    I know there is a standard Save As dialogue automatically launched by the browser. But my problem is: I don't need such a pumped-up Save As... dialogue which most brower will provide, because our system will have an interface which will provide the same function as the Save As guy. And this is the part that I am currently working on. Our interface will permit the client to browse their file system and then provide a filename, and then click OK to save the file. PLEASE, anybody who can help me. I know there are guys there have answers for my questions:
    1. In my JSP program, I save the resultset I get from the database as a string, and then this string should be sent through inputstream and outputstream and be saved as a text file onto the client's local machine. I know there's a lot file download topics but I am dealing with a string instead of a file, is there an inputstream accepting a string(which contains dataresultset) and output it to a file?
    2. As I already said, how to make my own Save As... dialogue?
    I really need help! I have been bothered by them for a long time. Thanks in advance!

    Well, it's hard to interpret exactly what you want to do but I'll take a stab.
    I would put the data into comma separated value (CSV) format and then stream it back to the browser using the "application/csv" content format.
    By doing this, they can either save it to their hard drive into the directory of their choice, or open it using whatever mapping they have for the CSV mime type. For most Windows machines, this is Excel (if it's loaded).

  • Problem in opening excel file in different window

    hi
    i want to open excel file in different window it open in same window properly on the bases of condition but when i try to open in different with window.open( )
    it give error that file has already used or path not exist OR requisted site either unavailable
    how can i rectified

    Hi.
    I am too facing the same problem. I am using Jakarta Poi to display my resultset in an excel sheet directly(and not into a jsp)
    The browser opens a window showing Open Save Cancel. If i click and save the excel sheet and then open, it opens. But clicking on Open directly doesnt open the excel sheet. Rather it gives the same error
    The file name or path name does not exist.
    The file you are trying to open is being used by another progrtam . close the document in other program and try again
    The name of the work book your tring to save is the same as name of another document that is readonly .try saving workbook with different name
    Can somebody please help me fix this problem, since its an urgent requirement. Mail me at [email protected]
    Thanks
    Hitesh

  • 100000 records resultset giving problem ?

    Hello All,
    I am using oracle database, windows 2000, OC4J(Oracle Containers for j2ee) Application Server. When I query a emp table which has 100000 records and store the 100000 records in resultset and using a while loop
    if I iterates through the resultset to store each emp record in emp bean array then my application hangs at this point so I am unable to form a emp bean array of 100000 records. What is the reason ?
    Also, I am getting 'OutOfMemoryError' exception at the client side(jsp) when I am trying iterate over a vector that stores each of 100000 emp records as inner vector. I tried to increase my system page file size(virtual memory) to 1GB but this didnt help. So how to avoid this error in windows2000 and on unix box.
    Thanks and Regards,
    Kumar.

    I'd guess the reason is memory related. The simple answer to your question is "don't do that!" Why would the user ever want to look at 100,000 records? If the result of a user request would give such a large number of hits, your app should ask the user to refine the search criteria.
    Even if browsing 100,000 rows really is a requirement (which seems doubtful), why read them all at one pass? You could store a reasonable number (e.g. 1,000) and request a new read every 1,000 records. Alternatively, store the 100,000 in a disk file and page from there.

  • Remove from Main Window

    Hi all,
    I'm having some trouble removing text from labels in my main window.
    I have a main window which has a JMenuBar. On the MenuBar I have a options > file> Remove Menu Item.
    When I select the Remove Menu Item, a Remove Dialog opens up with a JList and a Remove button.
    The JList is populated by a column (queueName) from my table "testtable".
    When I select a particular entry from the Jlist and click "Remove" the entry is removed from the list and my database but not from my main window.
    How can i go about removing entry from my main window??
    Here is the necessary code:
    public class MainWindowClass extends JFrame implements ActionListener {   
        private JPanel prodEastPanel;
        private JPanel prodPanel;
        private JPanel prodWestPanel;
        private JMenuBar menuBar = null;
        private JMenu fileMenu,  optionsMenu = null;
        private JMenuItem exitMI,  removeMI = null;
        JLabel[] prdLabelArray = new JLabel[12];
        ArrayList rec = new ArrayList();
        DBConnection dbc = new DBConnection();
        public MainWindowClass() {
            initComponents();
        private void initComponents() {
            prodPanel = new JPanel();
            prodWestPanel = new JPanel();
            prodEastPanel = new JPanel();
            for (int i = 0; i < prdLabelArray.length; i++) {
                prdLabelArray[i] = new JLabel("");
            menuBar = new JMenuBar();
            fileMenu = new JMenu("File");
            optionsMenu = new JMenu("Options");
            removeMI = new JMenuItem("Remove");
            removeMI.addActionListener(this);
            exitMI = new JMenuItem("Exit");
            exitMI.addActionListener(this);
            fileMenu.add(optionsMenu);
            optionsMenu.add(removeMI);
            fileMenu.add(exitMI);
            menuBar.add(fileMenu);
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setLayout(new GridLayout(1, 0));
            prodPanel.setBackground(new Color(255, 255, 255));
            prodPanel.setLayout(new GridLayout(0, 2));
            prodWestPanel.setBackground(new Color(255, 255, 255));
            prodWestPanel.setLayout(new GridLayout(6, 0));
            prodPanel.add(prodWestPanel);
            prodEastPanel.setBackground(new Color(255, 255, 255));
            prodEastPanel.setLayout(new GridLayout(6, 0));
            prodPanel.add(prodEastPanel);
            getContentPane().add(prodPanel);
            for (int l = 0; l < prdLabelArray.length; l++) {
                if (l % 2 == 0) {
                    prodWestPanel.add(prdLabelArray[l]);
                    prdLabelArray[l].setHorizontalTextPosition(SwingConstants.LEFT);
                } else {
                    prodEastPanel.add(prdLabelArray[l]);
                    prdLabelArray[l].setHorizontalTextPosition(SwingConstants.RIGHT);
            dbc.startConnection();
            rec = dbc.selectData();
            Iterator it = rec.iterator();
            while (it.hasNext()) {
                Store_DB_Data sd = (Store_DB_Data) it.next();
                if (sd.getQDescription().equals("PROD")) {
                    for (int i = 0; i < prdLabelArray.length; i++) {
                        if (prdLabelArray.getText() == "") {
    prdLabelArray[i].setText(sd.getQName().toUpperCase());
    break;
    dbc.closeSelect();
    setJMenuBar(menuBar);
    setTitle("Monitor");
    setSize(900, 500);
    MainWindowCloser brkWindowCloser = new MainWindowCloser();
    this.addWindowListener(brkWindowCloser);
    setVisible(true);
    pack();
    public MainWindowClass(String st, String st2) {
    initComponents();
    public void actionPerformed(ActionEvent ae) {
    Object source = ae.getSource();
    if (source == exitMI) {
    System.exit(0);
    if (source == removeMI) {
    new RemoveLabel();
    class MainWindowCloser extends WindowAdapter {
    public void windowClosing(WindowEvent we) {
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new MainWindowClass().setVisible(true);

    import java.io.Serializable;
    public class Store_DB_Data implements Serializable {
        private String qName;
        private String qDescription;
        public Store_DB_Data(String qName, String qDescription) {
            this.qName = qName;
            this.qDescription = qDescription;
        public String getQName() {
            return qName;
        public String getQDescription() {
            return qDescription;
        public void setQName(String quName) {
            qName = quName;
        public void setQDescription(String quDescription) {
            qDescription = quDescription;
    public class DBConnection {
        private Connection conn = null;
        private Statement stat = null;
        private ResultSet rs = null;
        public static String queueName;
        public static String description;
        public void startConnection() {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                System.out.println("Registered Driver");
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();           
            try {
                String userID = "";
                String psw = "";
                String url;
                url = "jdbc:mysql://localhost:3306/mqnames";
                conn = DriverManager.getConnection(url, userID, psw);
                stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_READ_ONLY);
            } catch (SQLException ex) {
                ex.printStackTrace();
        public ArrayList selectData() {
            ArrayList data = new ArrayList();
            try {
                String selectData = "SELECT queueName, description FROM testtable";
                rs = stat.executeQuery(selectData);
                while (rs.next()) {
                    queueName = rs.getString("queueName");
                    description = rs.getString("description");
                    data.add(new Store_DB_Data(queueName, description));
            } catch (SQLException e) {
                e.printStackTrace();
            return data;
        public void closeSelect() {
            try {
                rs.close();
                stat.close();
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
        public void deleteData(String removeName) {
            try {
                System.out.println("qName: " + removeName);
                stat = conn.createStatement();
                String deleteData = "DELETE FROM testtable WHERE queueName ='" + removeName + "'";
                int deleteCount = stat.executeUpdate(deleteData);           
                stat.close();
                conn.close();
                System.out.println("Connection for delete is closed");
            } catch (SQLException e) {
                e.printStackTrace();
        public ArrayList removeList() {
            ArrayList rData = new ArrayList();
            String names = new String();
            try {
                rs = stat.executeQuery("SELECT queueName FROM testtable");
                while (rs.next()) {
                    names = rs.getString("queueName");
                    System.out.println("rs: " + names);
                    rData.add(new RemoveData(names));
                rs.close();
            } catch (SQLException e) {
            return rData;
    }

  • Need to resize window to show all components !!

    I created a simple java application but there is a wiered problem. Unless i resize or maximise the window, I am unable to see any component I added into it. What is the problem with my code.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class CdApp implements ActionListener
         //Frame and Panel:-     
         JFrame cdFrame;
         JPanel cdPanel;
         static PreparedStatement val;
         static ResultSet result;
         int flag;
         //Buttons:-
         // Labels :-
         // Text Fields & Areas:-
         // Strings :-
         // Misc Components:-
         // The MainMethod :-
         public static void main(String[] args)
              CdApp cd_object1 = new CdApp();
              cd_object1.main_page();          
         // Methods:-
         // Main Page:-
         void main_page()
              cdPanel = new JPanel();
              cdFrame = new JFrame("CD Catalog Manager ===> Sukrit Mehra!!");
              cdFrame.setSize(800,600);
              cdFrame.setVisible(true);
              cdFrame.getContentPane().add(cdPanel);
              cdFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        

    can you cut and paste verbetim the following code into a CdApp.java file and compile it and run it and see if you can see a window 800x600 that displays "Hello I'm a JTextArea!" in the top middle to see if it displays without resizing?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class CdApp implements ActionListener{
         JFrame cdFrame;
         JPanel cdPanel;
            JTextArea jta;
            public static void main(String[] args){
                CdApp cd_object1 = new CdApp();
                cd_object1.main_page();
         void main_page(){
                cdPanel = new JPanel();
                cdPanel.add(new JTextArea("Hi I'm a JTextArea!"));
                cdFrame = new JFrame("CD Catalog Manager ===> Sukrit Mehra!!");
                cdFrame.setSize(800,600);                       
                cdFrame.getContentPane().add(cdPanel);
                cdFrame.setVisible(true);                       
                cdFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            public void actionPerformed(ActionEvent ae){       
    }

  • Problem with updateRow() of resultset

    When using JDBC-ODBC bridge accessing MS SQL Server 8.0.
    I issue the rs.updateRow(), and receive the following error:
    class java.sql.SQLException [Microsoft][ODBC SQL Server
    Driver]Invalid attribute/option identifier
    Any one out there have an idea ???
    Jagpate

    Hi Rolandpish:
    I'm using the following on Windows XP Pro:
    Product : Microsoft SQL Server, Version : Microsoft SQL Server  2000 - 8.00.760 (Intel X86)
               Dec 17 2002 14:22:05
               Copyright (c) 1988-2003 Microsoft Corporation
               Enterprise Evaluation Edition on Windows NT 5.1 (Build 2600: Service Pack 1)
    Driver : SQLServer, Version : 2.2.0029I haven't been able to get ResultSet.CONCUR_UPDATABLE.... how did you managed to get that accomplished (pls don't tell me it's because I'm using an Evaluation Edition).
    ;o)
    V.V.

Maybe you are looking for

  • Can't add events to iCloud calendars on my iPhone

    I have my phone and Mac set up on iCloud, and my iCloud calendars show up on my phone. But when I make a new event on my phone, I can't add them to my iCloud calendars. Thanks.

  • How do i type a pound sign on my macbook air?

    how do i type a pound sign on my macbook air?

  • ITubes cannot read iPod

    I get this error when I plug my iPod Shuffle to the USB Port: "iTunes cannot read the contents of the iPod "LUIS RODZ_S". Use the iPod Software Updater application to restore the iPod to factory settings." I updated the iPod Software but nothing happ

  • DVD video not recognised

    I bought a dvd and when i introduce it in to my computer ,it tells me is a blank dvd. I exchanged it in the store and i had the same problem But i have other dvds from the same brand and it works ,well it takes a while for my computer to open them bu

  • How can I erase the old e-mail accounts from the BB

    I just got a BB 8300 and I registered my account, but the previous owner´s e mail accounts still show in he screen. How can I get rid of them. Thx Solved! Go to Solution.