Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 98950 invoked from network); 19 Feb 2008 16:34:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Feb 2008 16:34:51 -0000 Received: (qmail 93845 invoked by uid 500); 19 Feb 2008 16:34:44 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 93822 invoked by uid 500); 19 Feb 2008 16:34:44 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 93811 invoked by uid 99); 19 Feb 2008 16:34:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2008 08:34:44 -0800 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of aceofspade1001@gmail.com designates 209.85.146.183 as permitted sender) Received: from [209.85.146.183] (HELO wa-out-1112.google.com) (209.85.146.183) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2008 16:34:10 +0000 Received: by wa-out-1112.google.com with SMTP id m38so4422192waf.5 for ; Tue, 19 Feb 2008 08:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=yIOkRPmKppQCfoVxaYqw+9FOKkrVtR21eDnoI5q2Gyo=; b=Aw3IepElmOtor5G+oZV9O+V8GcGXdvlSETAxQbxyWufq6NNWPIg9LNF7TpcyGR1U0+g+3gjdybE9XwYUU8KEhMzk7MhFtyAB10GdIVkYAnQ8zD4RY6qe3fmo8UnLul9b2hTnt+k3GyXsms0QQIbw4vNsOWrHozC7E/ocaY3MHJI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=HYw+JSHAaIwyts6tocPQiElwndVzN8N+iZdQ1bNCxqg9/AGfuHkUQ+Bjgpx9WjSMCS34ScAbp0rLVOhJ+Rk14dsdfzRMXcxdbgXeByIG5XiZ2Qbaa/o0ry89CIj9sPqUyJLCpmBxiT2ELVU6k0l3TC86mCUOTHvUy8sYbSKwQSg= Received: by 10.114.254.1 with SMTP id b1mr6002133wai.140.1203438857322; Tue, 19 Feb 2008 08:34:17 -0800 (PST) Received: by 10.115.93.12 with HTTP; Tue, 19 Feb 2008 08:34:17 -0800 (PST) Message-ID: <23ec26dc0802190834u642732cdtd87f79e3417547ef@mail.gmail.com> Date: Tue, 19 Feb 2008 21:34:17 +0500 From: "Waqar Hassan" To: "Derby Discussion" Subject: Re: Chat program using derby In-Reply-To: <15561400.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_15480_22023169.1203438857315" References: <15561400.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_15480_22023169.1203438857315 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline here is my code, String emps=""; try { Class.forName("org.apache.derdy.jdbc.EmbeddedDriver"); Connection c = null; c = DriverManager.getConnection("jdbc:derby://localhost:1527/hris1 [wack on WACK]","wack","wack"); Statement s = c.createStatement(); ResultSet rs = s.executeQuery("select empid,empname from WACK.empInfo"); while(rs.next()){ emps = "\n " ; emps = rs.getString("empname"); } jTextArea1.setText(emps); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } tell why m not having data in the jTextArea1 ??? Please Help i want to hav data in jTextArea1 On 2/19/08, musky wrote: > > > i am using derby server itself like a chat server. > > i have two programs:they both have a main thread which creates a user > interface. > as the user(say bob) enters his messages to the other party(say > alice),they > are entered into a table say bobtable. > there is a thread that is invoked periodically that reads unread messages > from alicetable and displays them to bob and updates the messages as read > by > setting the ID field to 1. > > the same logic is for alice. > > here are the programs: > > bob: > import java.util.Timer; > > import java.util.TimerTask; > import java.sql.*; > > import org.eclipse.swt.*; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.widgets.*; > > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.Text; > public class TestTime { > DBClass dbobject1=new DBClass(); > static MainClass mc; > static Statement stmt; > static Connection conn=null; > PreparedStatement pstmt=null; > static PreparedStatement pstmt1=null; > > ResultSet rs=null; > ResultSet rs1=null; > > static Display d; > static Shell s; > static Button OK; > > //int id=0; > > public static void main(String[] args) throws Exception { > TestTime t = new TestTime(); > > > DBClass dbobject1=new DBClass(); > conn=dbobject1.createConnection("ChatDB1"); > conn.setAutoCommit(false); > t.stmt = conn.createStatement(); > t.execute(); > //mc=new MainClass(); > > d = new Display( ); > s = new Shell(d); > s.setSize(250,250); > s.setText("A Text Field Example"); > > final Text text1 = new Text(s, SWT.MULTI | SWT.BORDER); > text1.setBounds(0,0,250,150); > OK = new Button(s, SWT.PUSH); > OK.setBounds(80,170,75,40); > OK.setText("OK"); > OK.addSelectionListener(new SelectionAdapter( ) { > public void widgetSelected(SelectionEvent e) > { > String contents = text1.getText( ); > text1.setText(""); > > > > System.out.println("Push Me Was Pushed"); > //System.out.println(contents); > try > { > //stmt.executeUpdate("lock table bobtable in exclusive > mode"); > pstmt1 = conn.prepareStatement("insert into bobtable > values(?,?)"); > pstmt1.setInt(1,0); > pstmt1.setString(2,contents); > > pstmt1.executeUpdate(); > System.out.println("inserted "+contents+" into bobtable"); > } > catch(Exception e1) > {System.out.println("could not insert"+e1);} > > } > > }); > > > s.open(); > > while(!s.isDisposed( )){ > if(!d.readAndDispatch( )) > d.sleep( ); > } > > System.out.println("Main Method is finishing"); > > } > > private void execute() throws Exception { > System.out.println(" Tasks scheduled"); > int initialDelay = 1000; // start after 30 seconds > int period = 2000; // repeat every 5 seconds > Timer timer = new Timer(); > System.out.println(" Timer set"); > > DBClass dbobject2=new DBClass(); > final Connection conn2=dbobject2.createConnection("ChatDB1"); > conn2.setAutoCommit(false); > stmt = conn2.createStatement(); > > > //dbclass db=new dbclass(); > > timer.scheduleAtFixedRate(new TimerTask () > { > public void run() > { > //System.out.println("Task Run"); > > //conn=dbobject1.createConnection("ChatDB1"); > > > try > { > //int id=mc.returnflag(); > > //System.out.println(id); > // System.out.println("Before ExecuteQuery"); > > //stmt.executeUpdate("lock table alicetable in share mode"); > > PreparedStatement pstmt=conn2.prepareStatement("select * from alicetable > where TID=0"); > //pstmt.setInt(1,id); > > rs=pstmt.executeQuery(); > //stmt.executeUpdate("lock table alicetable in exclusive mode"); > > stmt.executeUpdate("Update alicetable set TID=1 where TID=0"); > //rs1=pstmt.executeQuery(); > > > while(rs.next()) > { > String str=rs.getString(2); > int str2=rs.getInt(1); > System.out.println(str2+" "+str); > } > > > } > > catch ( Exception e ) {System.out.println("mhjfdshmnjh "+e);} > > } > }, initialDelay, period); > } > } > > alice: > import java.util.Timer; > > import java.util.TimerTask; > import java.sql.*; > > import org.eclipse.swt.*; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.widgets.*; > > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.Text; > public class TestTime2 { > DBClass dbobject1=new DBClass(); > static MainClass mc; > Statement stmt; > static Connection conn=null; > PreparedStatement pstmt=null; > static PreparedStatement pstmt1=null; > static Text text1; > ResultSet rs=null; > ResultSet rs1=null; > > static Display d; > static Shell s; > static Button OK; > > //int id=0; > > public static void main(String[] args) throws Exception { > TestTime2 t = new TestTime2(); > > > DBClass dbobject1=new DBClass(); > conn=dbobject1.createConnection("ChatDB1"); > conn.setAutoCommit(false); > t.execute(); > //mc=new MainClass(); > > d = new Display( ); > s = new Shell(d); > s.setSize(250,250); > s.setText("A Text Field Example"); > > text1 = new Text(s, SWT.MULTI | SWT.BORDER); > text1.setBounds(0,0,250,150); > OK = new Button(s, SWT.PUSH); > OK.setBounds(80,170,75,40); > OK.setText("OK"); > > OK.addSelectionListener(new SelectionAdapter( ) { > public void widgetSelected(SelectionEvent e) > { > String contents = text1.getText( ); > text1.setText(""); > > > > System.out.println("Push Me Was Pushed"); > //System.out.println(contents); > try > { > pstmt1 = conn.prepareStatement("insert into alicetable > values(?,?)"); > pstmt1.setInt(1,0); > pstmt1.setString(2,contents); > > pstmt1.executeUpdate(); > System.out.println("inserted "+contents+" into alicetable"); > } > catch(Exception e1) > {System.out.println("could not insert"+e1);} > > } > > }); > > > s.open(); > > while(!s.isDisposed( )){ > if(!d.readAndDispatch( )) > d.sleep( ); > } > > System.out.println("Main Method is finishing"); > > } > > private void execute() throws Exception { > System.out.println(" Tasks scheduled"); > int initialDelay = 10000; // start after 30 seconds > int period = 2000; // repeat every 5 seconds > Timer timer = new Timer(); > System.out.println(" Timer set"); > > DBClass dbobject2=new DBClass(); > final Connection conn2=dbobject2.createConnection("ChatDB1"); > conn2.setAutoCommit(false); > stmt = conn2.createStatement(); > //dbclass db=new dbclass(); > > timer.scheduleAtFixedRate(new TimerTask () > { > public void run() > { > try > { > PreparedStatement pstmt=conn2.prepareStatement("select * from bobtable > where > TID=0"); > //pstmt.setInt(1,id); > > rs=pstmt.executeQuery(); > //stmt.executeUpdate("lock table bobtable in exclusive mode"); > > stmt.executeUpdate("Update bobtable set TID=1 where TID=0"); > //rs1=pstmt.executeQuery(); > > > while(rs.next()) > { > String str=rs.getString(2); > int str2=rs.getInt(1); > System.out.println(str2+" "+str); > //text1.setText(str2+" "+str); > } > > > } > > catch ( Exception e ) {System.out.println("mhjfdshmnjh "+e);} > > } > }, initialDelay, period); > } > } > > when i run both the programs:i get the following exception:mhjfdshmnjh > java.sql.SQLTransactionRollbackException: A lock could not be obtained > within the time requested > > please help me. > > regards. > -- > View this message in context: > http://www.nabble.com/Chat-program-using-derby-tp15561400p15561400.html > Sent from the Apache Derby Users mailing list archive at Nabble.com. > > -- ! ! ! WACK ! ! ! ------=_Part_15480_22023169.1203438857315 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
here is my code,
   String emps="";
        try {
            Class.forName("org.apache.derdy.jdbc.EmbeddedDriver");
            Connection c = null;
            c = DriverManager.getConnection("jdbc:derby://localhost:1527/hris1 [wack on WACK]","wack","wack");
            Statement s = c.createStatement();
            ResultSet rs = s.executeQuery("select empid,empname from WACK.empInfo");
            while(rs.next()){
            emps = "\n " ;
            emps = rs.getString("empname");
            }
            jTextArea1.setText(emps);
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
 
tell why m not having data in the  jTextArea1 ???
Please Help
i want to hav data in  jTextArea1

 
On 2/19/08, musky <muskvar@gmail.com> wrote:

i am using derby server itself like a chat server.

i have two programs:they both have a main thread which creates a user
interface.
as the user(say bob) enters his  messages to the other party(say alice),they
are entered into a table say bobtable.
there is a thread that is invoked periodically that reads unread messages
from alicetable and displays them to bob and updates the messages as read by
setting the ID field to 1.

the same logic is for alice.

here are the programs:

bob:
import java.util.Timer;

import java.util.TimerTask;
import java.sql.*;

import org.eclipse.swt.*;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.*;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class TestTime {
         DBClass dbobject1=new DBClass();
         static MainClass mc;
         static Statement stmt;
         static Connection conn=null;
         PreparedStatement pstmt=null;
         static PreparedStatement pstmt1=null;

         ResultSet rs=null;
         ResultSet rs1=null;

         static Display d;
           static Shell s;
           static Button OK;

         //int id=0;

public static void main(String[] args) throws Exception {
TestTime t = new TestTime();


DBClass dbobject1=new DBClass();
conn=dbobject1.createConnection("ChatDB1");
conn.setAutoCommit(false);
t.stmt = conn.createStatement();
t.execute();
//mc=new MainClass();

d = new Display( );
s = new Shell(d);
s.setSize(250,250);
s.setText("A Text Field Example");

final Text text1 = new Text(s, SWT.MULTI | SWT.BORDER);
text1.setBounds(0,0,250,150);
OK = new Button(s, SWT.PUSH);
OK.setBounds(80,170,75,40);
OK.setText("OK");
OK.addSelectionListener(new SelectionAdapter( ) {
          public void widgetSelected(SelectionEvent e)
          {
                  String contents = text1.getText( );
                  text1.setText("");



                System.out.println("Push Me Was Pushed");
                //System.out.println(contents);
                try
               {
               //stmt.executeUpdate("lock table bobtable in exclusive mode");
               pstmt1 = conn.prepareStatement("insert into bobtable
values(?,?)");
               pstmt1.setInt(1,0);
               pstmt1.setString(2,contents);

           pstmt1.executeUpdate();
              System.out.println("inserted "+contents+" into bobtable");
               }
                catch(Exception e1)
               {System.out.println("could not insert"+e1);}

          }

       });


s.open();

while(!s.isDisposed( )){
   if(!d.readAndDispatch( ))
       d.sleep( );
}

System.out.println("Main Method is finishing");

}

private void execute() throws Exception {
System.out.println(" Tasks scheduled");
int initialDelay = 1000; // start after 30 seconds
int period = 2000; // repeat every 5 seconds
Timer timer = new Timer();
System.out.println(" Timer set");

DBClass dbobject2=new DBClass();
final Connection conn2=dbobject2.createConnection("ChatDB1");
conn2.setAutoCommit(false);
stmt = conn2.createStatement();


//dbclass db=new dbclass();

timer.scheduleAtFixedRate(new TimerTask ()
{
public void run()
{
//System.out.println("Task Run");

//conn=dbobject1.createConnection("ChatDB1");


try
{
       //int id=mc.returnflag();

       //System.out.println(id);
         // System.out.println("Before ExecuteQuery");

   //stmt.executeUpdate("lock table alicetable in share mode");

PreparedStatement pstmt=conn2.prepareStatement("select * from alicetable
where TID=0");
//pstmt.setInt(1,id);

rs=pstmt.executeQuery();
//stmt.executeUpdate("lock table alicetable in exclusive mode");

stmt.executeUpdate("Update alicetable set TID=1 where TID=0");
//rs1=pstmt.executeQuery();


while(rs.next())
  {
          String str=rs.getString(2);
          int str2=rs.getInt(1);
          System.out.println(str2+"          "+str);
  }


}

catch ( Exception e ) {System.out.println("mhjfdshmnjh  "+e);}

}
}, initialDelay, period);
}
}

alice:
import java.util.Timer;

import java.util.TimerTask;
import java.sql.*;

import org.eclipse.swt.*;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.*;

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class TestTime2 {
         DBClass dbobject1=new DBClass();
         static MainClass mc;
         Statement stmt;
         static Connection conn=null;
         PreparedStatement pstmt=null;
         static PreparedStatement pstmt1=null;
     static Text text1;
         ResultSet rs=null;
         ResultSet rs1=null;

         static Display d;
           static Shell s;
           static Button OK;

         //int id=0;

public static void main(String[] args) throws Exception {
TestTime2 t = new TestTime2();


DBClass dbobject1=new DBClass();
conn=dbobject1.createConnection("ChatDB1");
conn.setAutoCommit(false);
t.execute();
//mc=new MainClass();

d = new Display( );
s = new Shell(d);
s.setSize(250,250);
s.setText("A Text Field Example");

text1 = new Text(s, SWT.MULTI | SWT.BORDER);
text1.setBounds(0,0,250,150);
OK = new Button(s, SWT.PUSH);
OK.setBounds(80,170,75,40);
OK.setText("OK");

OK.addSelectionListener(new SelectionAdapter( ) {
          public void widgetSelected(SelectionEvent e)
          {
                  String contents = text1.getText( );
                  text1.setText("");



                System.out.println("Push Me Was Pushed");
                //System.out.println(contents);
                try
               {
               pstmt1 = conn.prepareStatement("insert into alicetable
values(?,?)");
               pstmt1.setInt(1,0);
               pstmt1.setString(2,contents);

           pstmt1.executeUpdate();
              System.out.println("inserted "+contents+" into alicetable");
               }
                catch(Exception e1)
               {System.out.println("could not insert"+e1);}

          }

       });


s.open();

while(!s.isDisposed( )){
   if(!d.readAndDispatch( ))
       d.sleep( );
}

System.out.println("Main Method is finishing");

}

private void execute() throws Exception {
System.out.println(" Tasks scheduled");
int initialDelay = 10000; // start after 30 seconds
int period = 2000; // repeat every 5 seconds
Timer timer = new Timer();
System.out.println(" Timer set");

DBClass dbobject2=new DBClass();
final Connection conn2=dbobject2.createConnection("ChatDB1");
conn2.setAutoCommit(false);
stmt = conn2.createStatement();
//dbclass db=new dbclass();

timer.scheduleAtFixedRate(new TimerTask ()
{
public void run()
{
try
{
PreparedStatement pstmt=conn2.prepareStatement("select * from bobtable where
TID=0");
//pstmt.setInt(1,id);

rs=pstmt.executeQuery();
//stmt.executeUpdate("lock table bobtable in exclusive mode");

stmt.executeUpdate("Update bobtable set TID=1 where TID=0");
//rs1=pstmt.executeQuery();


while(rs.next())
  {
          String str=rs.getString(2);
          int str2=rs.getInt(1);
          System.out.println(str2+"          "+str);
          //text1.setText(str2+"                 "+str);
  }


}

catch ( Exception e ) {System.out.println("mhjfdshmnjh  "+e);}

}
}, initialDelay, period);
}
}

when i run both the programs:i get the following exception:mhjfdshmnjh
java.sql.SQLTransactionRollbackException: A lock could not be obtained
within the time requested

please help me.

regards.
--
View this message in context: http://www.nabble.com/Chat-program-using-derby-tp15561400p15561400.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.




--
! ! ! WACK ! ! ! ------=_Part_15480_22023169.1203438857315--