You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by musky <mu...@gmail.com> on 2008/02/13 16:05:35 UTC
Using derby as a chat server
i want to use derby as a chat server,
my idea is to insert whatever a user types into a table in the database.This
table can have two fields UserID and the message(VARCHAR).how do i convey
the inserted message to the other party??
please help.
thanks.
--
View this message in context: http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15459468.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: Using derby as a chat server
Posted by musky <mu...@gmail.com>.
i have come up with a basic framework for the application:
there will be two treads:
one thread takes care of the GUI and taking user chat messages from the
keyboard onto a textbox.
the second thread will select the most recent message for the user from the
other party every "n" seconds.i will be using the java.util.timer package
for this.
does anybody know whether derby can put up with so many connections?
please give me your insights as i am still a newbie who wants to do
something new and i am doing my undergrad now.
francois.orsini wrote:
>
> Hi Musky,
>
> Jean-Francois Arcand (Grizzly / Comet project lead) and myself have
> demo'ed
> a chat server application with Derby at ApacheCon US and JavaPolis.
>
> We are working on a more generic framework that we intend to make
> available
> as part of some open source project (sub-project of Grizzly very likely).
> In
> the meantime, I'm going to post the source code and necessary archives on
> my
> blog. You can also find additional resources at:
>
> http://weblogs.java.net/blog/jfarcand/archive/2007/12/on_the_roadto_j_5.html
> http://blogs.sun.com/FrancoisOrsini/entry/developing_real_time_ria_with
>
> You can check the slides we presented for more info, especially about
> Comet,
> if you're not familiar with it yet.
>
> The idea behind this demo is to show the *multi-tier* aspect of Apache
> Derby. In this particular context, Derby is installed automatically and
> run
> (embedded) within the web browser as a Java plug-in extension. On this RIA
> client, Derby is used to store 'chat' conversation messages for any
> (signed-on) user that would use the chat application in that client.
> Messages are made persistent so that they can be re-read / re-accessed
> offline and you only get to see the messages for a particular user
> (obviously) - Messages could also be created *offline* so that the next
> time
> you're online, they get sent to the chat server. Derby runs embedded in
> the
> server to handle *overflow *of incoming and asynchronous messages,
> dispatched by *Comet*. Derby basically acts as an efficient and persistent
> cache to store data asynchronously, in this case, flux of incoming and
> outgoing network messages, handled by Comet.
>
> I'll post back here when archives are available for download.
>
> Cheers,
>
> --francois
>
> On Feb 13, 2008 7:05 AM, musky <mu...@gmail.com> wrote:
>
>>
>> i want to use derby as a chat server,
>> my idea is to insert whatever a user types into a table in the
>> database.This
>> table can have two fields UserID and the message(VARCHAR).how do i convey
>> the inserted message to the other party??
>>
>> please help.
>>
>> thanks.
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15459468.html
>> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15476615.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: Using derby as a chat server
Posted by Francois Orsini <fr...@gmail.com>.
Hi Musky,
Jean-Francois Arcand (Grizzly / Comet project lead) and myself have demo'ed
a chat server application with Derby at ApacheCon US and JavaPolis.
We are working on a more generic framework that we intend to make available
as part of some open source project (sub-project of Grizzly very likely). In
the meantime, I'm going to post the source code and necessary archives on my
blog. You can also find additional resources at:
http://weblogs.java.net/blog/jfarcand/archive/2007/12/on_the_roadto_j_5.html
http://blogs.sun.com/FrancoisOrsini/entry/developing_real_time_ria_with
You can check the slides we presented for more info, especially about Comet,
if you're not familiar with it yet.
The idea behind this demo is to show the *multi-tier* aspect of Apache
Derby. In this particular context, Derby is installed automatically and run
(embedded) within the web browser as a Java plug-in extension. On this RIA
client, Derby is used to store 'chat' conversation messages for any
(signed-on) user that would use the chat application in that client.
Messages are made persistent so that they can be re-read / re-accessed
offline and you only get to see the messages for a particular user
(obviously) - Messages could also be created *offline* so that the next time
you're online, they get sent to the chat server. Derby runs embedded in the
server to handle *overflow *of incoming and asynchronous messages,
dispatched by *Comet*. Derby basically acts as an efficient and persistent
cache to store data asynchronously, in this case, flux of incoming and
outgoing network messages, handled by Comet.
I'll post back here when archives are available for download.
Cheers,
--francois
On Feb 13, 2008 7:05 AM, musky <mu...@gmail.com> wrote:
>
> i want to use derby as a chat server,
> my idea is to insert whatever a user types into a table in the
> database.This
> table can have two fields UserID and the message(VARCHAR).how do i convey
> the inserted message to the other party??
>
> please help.
>
> thanks.
>
>
> --
> View this message in context:
> http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15459468.html
> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>
>
Re: Using derby as a chat server
Posted by Francois Orsini <fr...@gmail.com>.
On Wed, Feb 13, 2008 at 7:18 AM, Kurt Huwig <ku...@scooter-attack.com> wrote:
> Forget about Derby for chat and have a look at JMS. This is a good
> implementation:
>
> http://joram.objectweb.org/
You can't compare Derby with JORAM. In a particular application such as a
chat server, Derby would be used to store messages, be them on the client
or/and server side...This has nothing to do with the actual protocol (e.g.
MoM) implementing messaging between endpoints...If you want to compare
apples to apples then JORAM would have to be compared with *Comet*,
*not*Derby which is just a mere persistent store for a disconnected
mode or to
offload a server where there would just be too many incoming messages to
process in real-time (for instance), if that server would provide services
on a WAN....Derby could very well be used with JORAM as well...
<http://joram.objectweb.org/>
>
> Am Mittwoch, 13. Februar 2008 schrieb musky:
> > also i dont want to use any sockets.
> > all the chat clients connect to the database server.
> >
> > musky wrote:
> > > i want to use derby as a chat server,
> > > my idea is to insert whatever a user types into a table in the
> > > database.This table can have two fields UserID and the
> > > message(VARCHAR).how do i convey the inserted message to the other
> > > party??
> > >
> > > please help.
> > >
> > > thanks.
>
>
>
> --
> Mit freundlichen Grüßen
>
> ........................................................................................................
> Kurt Huwig - Leiter IT-Abteilung
>
> www.scooter-attack.com
> IT Park Saarland | Altenkesseler Str. 17/C1 | D-66115 Saarbrücken
> Phone: +49-(0)-681-9762-371 | Fax: +49-(0)-681-9762-373
>
> Aktuelle News: www.scooter-attack.com/news/
> need for speed? ... amphetamine your engine!
>
> HRB 12678 Saarbrücken | Geschäftsführer Magnus Köpfer, Thilo Nast
>
Re: Using derby as a chat server
Posted by Daniel Noll <da...@nuix.com>.
On Thursday 14 February 2008 02:18:54 Kurt Huwig wrote:
> Forget about Derby for chat and have a look at JMS. This is a good
> implementation:
>
> http://joram.objectweb.org/
Or use something actually designed to be a chat server, such as Openfire.
Daniel
Re: Using derby as a chat server
Posted by Suavi Ali Demir <de...@yahoo.com>.
Have a table where you have 1 row that marks the relationship between two clients. Like a cartesian product:
A, B
A, C
A, D
B, A
B, C
B, D
..and so on.
Have all clients have their dedicated connection acquire locks on these rows. Each lock represents a client that may post a message.
Have all clients have 1 connection per potential message source client. Have each of these connections attempt a commited read on respective row on separate threads.
For example, A will have a connection waiting on row B->A, another connection on C->A, etc.
When B posts a message to A, it will insert it into messages table and it will release it's lock on B->A row (and B->C, B->D etc) in the locks table. This will cause A's lock waiting connection to return the result which indicates B posted a message. Within this thread (of A), you need to read messages table with a repeatable read and before you release that repeatable read lock, A needs to start waiting on lock B->A again, so that B does not post another msg to A while A is not looking. But for this to happen, B must have locked B->A by now. When should B lock B->A again? I dont' know yet. Figuring that out is left to the reader as an exercise. LOL. (Please let me know if you make this work)
Better have a row version that is incremented per row in the messages table so that you read only after that level and keep it as current client version to use as water mark until next time.
This is alot of total connections but if you got enough memory, it should work. I did not try this, there may be problems when you actually try. Lock escalation may cause problems. Maybe Derby has a way to disable lock escalation. You may be able to reduce number of connections by thinking in a smarter way to maintain your locks via persisted state info in another table(s).
JMS might be easier and use less threads with async io.
Regards,
Ali
Kurt Huwig <ku...@scooter-attack.com> wrote:
Forget about Derby for chat and have a look at JMS. This is a good
implementation:
http://joram.objectweb.org/
Am Mittwoch, 13. Februar 2008 schrieb musky:
> also i dont want to use any sockets.
> all the chat clients connect to the database server.
>
> musky wrote:
> > i want to use derby as a chat server,
> > my idea is to insert whatever a user types into a table in the
> > database.This table can have two fields UserID and the
> > message(VARCHAR).how do i convey the inserted message to the other
> > party??
> >
> > please help.
> >
> > thanks.
--
Mit freundlichen Gr��en
........................................................................................................
Kurt Huwig - Leiter IT-Abteilung
www.scooter-attack.com
IT Park Saarland | Altenkesseler Str. 17/C1 | D-66115 Saarbr�cken
Phone: +49-(0)-681-9762-371 | Fax: +49-(0)-681-9762-373
Aktuelle News: www.scooter-attack.com/news/
need for speed? ... amphetamine your engine!
HRB 12678 Saarbr�cken | Gesch�ftsf�hrer Magnus K�pfer, Thilo Nast
---------------------------------
Never miss a thing. Make Yahoo your homepage.
Re: Using derby as a chat server
Posted by Kurt Huwig <ku...@scooter-attack.com>.
Forget about Derby for chat and have a look at JMS. This is a good
implementation:
http://joram.objectweb.org/
Am Mittwoch, 13. Februar 2008 schrieb musky:
> also i dont want to use any sockets.
> all the chat clients connect to the database server.
>
> musky wrote:
> > i want to use derby as a chat server,
> > my idea is to insert whatever a user types into a table in the
> > database.This table can have two fields UserID and the
> > message(VARCHAR).how do i convey the inserted message to the other
> > party??
> >
> > please help.
> >
> > thanks.
--
Mit freundlichen Grüßen
........................................................................................................
Kurt Huwig - Leiter IT-Abteilung
www.scooter-attack.com
IT Park Saarland | Altenkesseler Str. 17/C1 | D-66115 Saarbrücken
Phone: +49-(0)-681-9762-371 | Fax: +49-(0)-681-9762-373
Aktuelle News: www.scooter-attack.com/news/
need for speed? ... amphetamine your engine!
HRB 12678 Saarbrücken | Geschäftsführer Magnus Köpfer, Thilo Nast
Re: Using derby as a chat server
Posted by musky <mu...@gmail.com>.
here is the code for the chat application:
it is very very crude and is only experimental code:
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;
/**
* Simple demo that uses java.util.Timer to schedule a task to execute
* once 5 seconds have passed.
*/ public class TestTime {
DBClass dbobject1=new DBClass();
static MainClass mc;
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();
try
{
t.stmt.executeUpdate( "DROP TABLE chattable" );
System.out.println(
"Table chattable was removed.");
}
catch ( Exception e ) {}
try
{
// may need modification for your database
t.stmt.executeUpdate( "CREATE TABLE chattable(TID INT,Tchat VARCHAR
(255))" );
System.out.println(
"Table chatable was created.");
}
catch( Exception e )
{
System.out.println("could not create chattable"+e);
}
/*
try
{
t.stmt.executeUpdate("insert into chattable values(0,'HI')");
System.out.println("INSERTED");
t.stmt.executeUpdate("insert into chattable values(1,'HI MAN')");
System.out.println("INSERTED");
t.stmt.executeUpdate("insert into chattable values(2,'HI MAN HOW ARE
YOU')");
System.out.println("INSERTED");
}
catch( Exception e )
{
System.out.println("could not insert into chattable"+e);
}
*/
/*try { t.stmt.close(); }
catch( Exception e ) {}*/
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
{
pstmt1 = conn.prepareStatement("insert into chattable
values(?,?)");
pstmt1.setInt(1,0);
pstmt1.setString(2,contents);
pstmt1.executeUpdate();
System.out.println("inserted "+contents+" into table");
}
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 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");
PreparedStatement pstmt=conn.prepareStatement("select * from chattable where
TID=0");
//pstmt.setInt(1,id);
rs=pstmt.executeQuery();
stmt.executeUpdate("Update chattable 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);
}
}
any suggestions.
thanks.
musky wrote:
>
> i solved it it was because of:
> id=mc.returnflag();
>
> sorry for this.
>
>
> musky wrote:
>>
>> i have the following code fao a thread that will select from a table
>> periodically.
>> here it is:
>> import java.util.Timer;
>> import java.util.TimerTask;
>> import java.sql.*;
>> /**
>> * Simple demo that uses java.util.Timer to schedule a task to execute
>> * once 5 seconds have passed.
>> */ public class TestTime {
>> DBClass dbobject1=new DBClass();
>> MainClass mc;
>> Statement stmt;
>> static Connection conn=null;
>> PreparedStatement pstmt=null;
>> ResultSet rs=null;
>> int id=0;
>>
>> public static void main(String[] args) throws Exception {
>> TestTime t = new TestTime();
>>
>> //MainClass mc=new MainClass();
>> DBClass dbobject1=new DBClass();
>> conn=dbobject1.createConnection("ChatDB1");
>> t.stmt = conn.createStatement();
>> try
>> {
>> t.stmt.executeUpdate( "DROP TABLE chattable" );
>> System.out.println(
>> "Table chattable was removed.");
>> }
>> catch ( Exception e ) {
>> /* don't care */ }
>>
>> try
>> {
>>
>> // may need modification for your database
>> t.stmt.executeUpdate( "CREATE TABLE chattable(TID INT,Tchat VARCHAR
>> (255))" );
>>
>> System.out.println(
>> "Table chatable was created.");
>>
>>
>>
>>
>> }
>> catch( Exception e )
>> {
>> System.out.println("could not create chattable"+e);
>> }
>>
>>
>> try
>> {
>> t.stmt.executeUpdate("insert into chattable values(0,'HI')");
>> System.out.println("INSERTED");
>> t.stmt.executeUpdate("insert into chattable values(1,'HI MAN')");
>> System.out.println("INSERTED");
>>
>> t.stmt.executeUpdate("insert into chattable values(2,'HI MAN HOW ARE
>> YOU')");
>> System.out.println("INSERTED");
>> }
>> catch( Exception e )
>> {
>> System.out.println("could not insert into chattable"+e);
>> }
>>
>>
>>
>>
>> try { t.stmt.close(); }
>> catch( Exception e ) {}
>>
>>
>>
>> t.execute();
>> 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 db=new dbclass();
>>
>> timer.scheduleAtFixedRate(new TimerTask ()
>> {
>> public void run()
>> {
>> System.out.println("Task Run");
>> //conn=dbobject1.createConnection("ChatDB1");
>>
>>
>> try
>> {
>> id=mc.returnflag();
>> //System.out.println(id);
>> // System.out.println("Before ExecuteQuery");
>>
>> pstmt=conn.prepareStatement("select * from chattable");
>> //pstmt.setInt(1,id);
>>
>> rs=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);
>> }
>> }
>>
>> am getting nullpointerexception.
>>
>> please help.
>> thanks
>>
>>
>> Donald McLean-3 wrote:
>>>
>>> Yes, you would use a timer. You'll have to experiment with the timing
>>> (too
>>> often and it thrashes).
>>>
>>> You would select any message newer than the last message that was
>>> retrieved.
>>>
>>> On Feb 13, 2008 7:49 PM, musky <mu...@gmail.com> wrote:
>>>
>>>>
>>>> then how do i have a thread periodically select the latest message from
>>>> the
>>>> table?
>>>> should i use a timer or something
>>>>
>>>> Donald McLean-3 wrote:
>>>> >
>>>> > You might also want to have a messageID and maybe a messageTimestamp.
>>>> >
>>>> > If everyone is connecting directly to the database server then you're
>>>> just
>>>> > going to have to do a select periodically to see if anyone posted
>>>> anything
>>>> > new.
>>>> >
>>>> > I don't know what kind of connection limits a database server has,
>>>> but
>>>> if
>>>> > your target audience is large enough, your architecture could break
>>>> down
>>>> > (or
>>>> > even just bog down).
>>>> >
>>>> > On Feb 13, 2008 10:06 AM, musky <mu...@gmail.com> wrote:
>>>> >
>>>> >>
>>>> >> also i dont want to use any sockets.
>>>> >> all the chat clients connect to the database server.
>>>> >>
>>>> >> musky wrote:
>>>> >> >
>>>> >> > i want to use derby as a chat server,
>>>> >> > my idea is to insert whatever a user types into a table in the
>>>> >> > database.This table can have two fields UserID and the
>>>> >> > message(VARCHAR).how do i convey the inserted message to the other
>>>> >> party??
>>>>
>>>>
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15481670.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: Using derby as a chat server
Posted by musky <mu...@gmail.com>.
i solved it it was because of:
id=mc.returnflag();
sorry for this.
musky wrote:
>
> i have the following code fao a thread that will select from a table
> periodically.
> here it is:
> import java.util.Timer;
> import java.util.TimerTask;
> import java.sql.*;
> /**
> * Simple demo that uses java.util.Timer to schedule a task to execute
> * once 5 seconds have passed.
> */ public class TestTime {
> DBClass dbobject1=new DBClass();
> MainClass mc;
> Statement stmt;
> static Connection conn=null;
> PreparedStatement pstmt=null;
> ResultSet rs=null;
> int id=0;
>
> public static void main(String[] args) throws Exception {
> TestTime t = new TestTime();
>
> //MainClass mc=new MainClass();
> DBClass dbobject1=new DBClass();
> conn=dbobject1.createConnection("ChatDB1");
> t.stmt = conn.createStatement();
> try
> {
> t.stmt.executeUpdate( "DROP TABLE chattable" );
> System.out.println(
> "Table chattable was removed.");
> }
> catch ( Exception e ) {
> /* don't care */ }
>
> try
> {
>
> // may need modification for your database
> t.stmt.executeUpdate( "CREATE TABLE chattable(TID INT,Tchat VARCHAR
> (255))" );
>
> System.out.println(
> "Table chatable was created.");
>
>
>
>
> }
> catch( Exception e )
> {
> System.out.println("could not create chattable"+e);
> }
>
>
> try
> {
> t.stmt.executeUpdate("insert into chattable values(0,'HI')");
> System.out.println("INSERTED");
> t.stmt.executeUpdate("insert into chattable values(1,'HI MAN')");
> System.out.println("INSERTED");
>
> t.stmt.executeUpdate("insert into chattable values(2,'HI MAN HOW ARE
> YOU')");
> System.out.println("INSERTED");
> }
> catch( Exception e )
> {
> System.out.println("could not insert into chattable"+e);
> }
>
>
>
>
> try { t.stmt.close(); }
> catch( Exception e ) {}
>
>
>
> t.execute();
> 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 db=new dbclass();
>
> timer.scheduleAtFixedRate(new TimerTask ()
> {
> public void run()
> {
> System.out.println("Task Run");
> //conn=dbobject1.createConnection("ChatDB1");
>
>
> try
> {
> id=mc.returnflag();
> //System.out.println(id);
> // System.out.println("Before ExecuteQuery");
>
> pstmt=conn.prepareStatement("select * from chattable");
> //pstmt.setInt(1,id);
>
> rs=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);
> }
> }
>
> am getting nullpointerexception.
>
> please help.
> thanks
>
>
> Donald McLean-3 wrote:
>>
>> Yes, you would use a timer. You'll have to experiment with the timing
>> (too
>> often and it thrashes).
>>
>> You would select any message newer than the last message that was
>> retrieved.
>>
>> On Feb 13, 2008 7:49 PM, musky <mu...@gmail.com> wrote:
>>
>>>
>>> then how do i have a thread periodically select the latest message from
>>> the
>>> table?
>>> should i use a timer or something
>>>
>>> Donald McLean-3 wrote:
>>> >
>>> > You might also want to have a messageID and maybe a messageTimestamp.
>>> >
>>> > If everyone is connecting directly to the database server then you're
>>> just
>>> > going to have to do a select periodically to see if anyone posted
>>> anything
>>> > new.
>>> >
>>> > I don't know what kind of connection limits a database server has, but
>>> if
>>> > your target audience is large enough, your architecture could break
>>> down
>>> > (or
>>> > even just bog down).
>>> >
>>> > On Feb 13, 2008 10:06 AM, musky <mu...@gmail.com> wrote:
>>> >
>>> >>
>>> >> also i dont want to use any sockets.
>>> >> all the chat clients connect to the database server.
>>> >>
>>> >> musky wrote:
>>> >> >
>>> >> > i want to use derby as a chat server,
>>> >> > my idea is to insert whatever a user types into a table in the
>>> >> > database.This table can have two fields UserID and the
>>> >> > message(VARCHAR).how do i convey the inserted message to the other
>>> >> party??
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15481249.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: Using derby as a chat server
Posted by musky <mu...@gmail.com>.
i have the following code fao a thread that will select from a table
periodically.
here it is:
import java.util.Timer;
import java.util.TimerTask;
import java.sql.*;
/**
* Simple demo that uses java.util.Timer to schedule a task to execute
* once 5 seconds have passed.
*/ public class TestTime {
DBClass dbobject1=new DBClass();
MainClass mc;
Statement stmt;
static Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
int id=0;
public static void main(String[] args) throws Exception {
TestTime t = new TestTime();
//MainClass mc=new MainClass();
DBClass dbobject1=new DBClass();
conn=dbobject1.createConnection("ChatDB1");
t.stmt = conn.createStatement();
try
{
t.stmt.executeUpdate( "DROP TABLE chattable" );
System.out.println(
"Table chattable was removed.");
}
catch ( Exception e ) {
/* don't care */ }
try
{
// may need modification for your database
t.stmt.executeUpdate( "CREATE TABLE chattable(TID INT,Tchat VARCHAR
(255))" );
System.out.println(
"Table chatable was created.");
}
catch( Exception e )
{
System.out.println("could not create chattable"+e);
}
try
{
t.stmt.executeUpdate("insert into chattable values(0,'HI')");
System.out.println("INSERTED");
t.stmt.executeUpdate("insert into chattable values(1,'HI MAN')");
System.out.println("INSERTED");
t.stmt.executeUpdate("insert into chattable values(2,'HI MAN HOW ARE
YOU')");
System.out.println("INSERTED");
}
catch( Exception e )
{
System.out.println("could not insert into chattable"+e);
}
try { t.stmt.close(); }
catch( Exception e ) {}
t.execute();
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 db=new dbclass();
timer.scheduleAtFixedRate(new TimerTask ()
{
public void run()
{
System.out.println("Task Run");
//conn=dbobject1.createConnection("ChatDB1");
try
{
id=mc.returnflag();
//System.out.println(id);
// System.out.println("Before ExecuteQuery");
pstmt=conn.prepareStatement("select * from chattable");
//pstmt.setInt(1,id);
rs=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);
}
}
am getting nullpointerexception.
please help.
thanks
Donald McLean-3 wrote:
>
> Yes, you would use a timer. You'll have to experiment with the timing (too
> often and it thrashes).
>
> You would select any message newer than the last message that was
> retrieved.
>
> On Feb 13, 2008 7:49 PM, musky <mu...@gmail.com> wrote:
>
>>
>> then how do i have a thread periodically select the latest message from
>> the
>> table?
>> should i use a timer or something
>>
>> Donald McLean-3 wrote:
>> >
>> > You might also want to have a messageID and maybe a messageTimestamp.
>> >
>> > If everyone is connecting directly to the database server then you're
>> just
>> > going to have to do a select periodically to see if anyone posted
>> anything
>> > new.
>> >
>> > I don't know what kind of connection limits a database server has, but
>> if
>> > your target audience is large enough, your architecture could break
>> down
>> > (or
>> > even just bog down).
>> >
>> > On Feb 13, 2008 10:06 AM, musky <mu...@gmail.com> wrote:
>> >
>> >>
>> >> also i dont want to use any sockets.
>> >> all the chat clients connect to the database server.
>> >>
>> >> musky wrote:
>> >> >
>> >> > i want to use derby as a chat server,
>> >> > my idea is to insert whatever a user types into a table in the
>> >> > database.This table can have two fields UserID and the
>> >> > message(VARCHAR).how do i convey the inserted message to the other
>> >> party??
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15481237.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: Using derby as a chat server
Posted by Donald McLean <dm...@gmail.com>.
Yes, you would use a timer. You'll have to experiment with the timing (too
often and it thrashes).
You would select any message newer than the last message that was retrieved.
On Feb 13, 2008 7:49 PM, musky <mu...@gmail.com> wrote:
>
> then how do i have a thread periodically select the latest message from
> the
> table?
> should i use a timer or something
>
> Donald McLean-3 wrote:
> >
> > You might also want to have a messageID and maybe a messageTimestamp.
> >
> > If everyone is connecting directly to the database server then you're
> just
> > going to have to do a select periodically to see if anyone posted
> anything
> > new.
> >
> > I don't know what kind of connection limits a database server has, but
> if
> > your target audience is large enough, your architecture could break down
> > (or
> > even just bog down).
> >
> > On Feb 13, 2008 10:06 AM, musky <mu...@gmail.com> wrote:
> >
> >>
> >> also i dont want to use any sockets.
> >> all the chat clients connect to the database server.
> >>
> >> musky wrote:
> >> >
> >> > i want to use derby as a chat server,
> >> > my idea is to insert whatever a user types into a table in the
> >> > database.This table can have two fields UserID and the
> >> > message(VARCHAR).how do i convey the inserted message to the other
> >> party??
>
>
Re: Using derby as a chat server
Posted by musky <mu...@gmail.com>.
then how do i have a thread periodically select the latest message from the
table?
should i use a timer or something
please help.
Donald McLean-3 wrote:
>
> You might also want to have a messageID and maybe a messageTimestamp.
>
> If everyone is connecting directly to the database server then you're just
> going to have to do a select periodically to see if anyone posted anything
> new.
>
> I don't know what kind of connection limits a database server has, but if
> your target audience is large enough, your architecture could break down
> (or
> even just bog down).
>
> On Feb 13, 2008 10:06 AM, musky <mu...@gmail.com> wrote:
>
>>
>> also i dont want to use any sockets.
>> all the chat clients connect to the database server.
>>
>> musky wrote:
>> >
>> > i want to use derby as a chat server,
>> > my idea is to insert whatever a user types into a table in the
>> > database.This table can have two fields UserID and the
>> > message(VARCHAR).how do i convey the inserted message to the other
>> party??
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15471670.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: Using derby as a chat server
Posted by Donald McLean <dm...@gmail.com>.
You might also want to have a messageID and maybe a messageTimestamp.
If everyone is connecting directly to the database server then you're just
going to have to do a select periodically to see if anyone posted anything
new.
I don't know what kind of connection limits a database server has, but if
your target audience is large enough, your architecture could break down (or
even just bog down).
On Feb 13, 2008 10:06 AM, musky <mu...@gmail.com> wrote:
>
> also i dont want to use any sockets.
> all the chat clients connect to the database server.
>
> musky wrote:
> >
> > i want to use derby as a chat server,
> > my idea is to insert whatever a user types into a table in the
> > database.This table can have two fields UserID and the
> > message(VARCHAR).how do i convey the inserted message to the other
> party??
>
>
Re: Using derby as a chat server
Posted by musky <mu...@gmail.com>.
also i dont want to use any sockets.
all the chat clients connect to the database server.
musky wrote:
>
> i want to use derby as a chat server,
> my idea is to insert whatever a user types into a table in the
> database.This table can have two fields UserID and the
> message(VARCHAR).how do i convey the inserted message to the other party??
>
> please help.
>
> thanks.
>
>
>
--
View this message in context: http://www.nabble.com/Using-derby-as-a-chat-server-tp15459468p15459485.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.