473,574 Members | 18,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to connect mysql with ECLIPSE in RCP application

87 New Member
Hi

I dont know how to connect mysql with ECLIPSE in RCP application. Please send me the sample code of connecting mysql sever with ECLIPSE in RCP application.

Coding Part:

RCP Application Codes:

Class ApplicationActi onBarAdvisor:

import org.eclipse.jfa ce.action.Actio n;
import org.eclipse.jfa ce.action.IMenu Manager;
import org.eclipse.jfa ce.action.MenuM anager;
import org.eclipse.jfa ce.action.Separ ator;
import org.eclipse.ui. IWorkbenchActio nConstants;
import org.eclipse.ui. IWorkbenchWindo w;
import org.eclipse.ui. actions.ActionF actory;
import org.eclipse.ui. actions.ActionF actory.IWorkben chAction;
import org.eclipse.ui. application.Act ionBarAdvisor;
import org.eclipse.ui. application.IAc tionBarConfigur er;

public class ApplicationActi onBarAdvisor extends ActionBarAdviso r {

private Action addmember;

public ApplicationActi onBarAdvisor(IA ctionBarConfigu rer configurer) {
super(configure r);
}

protected void makeActions(IWo rkbenchWindow window) {

addmember=new Addmember("Add a Member",window) ;
register(addmem ber);

}

protected void fillMenuBar(IMe nuManager menuBar) {

MenuManager File=new MenuManager("&F ile",IWorkbench ActionConstants .M_FILE);
MenuManager Member=new MenuManager("&M ember",null);
menuBar.add(Fil e);
File.add(Member );
Member.add(addm ember);
}
}

Class Addmember:

import org.eclipse.jfa ce.action.Actio n;
import org.eclipse.ui. IWorkbenchWindo w;

public class Addmember extends Action {

private IWorkbenchWindo w window;
//public static boolean internalCall = false;

//public Addmember(){ };

public Addmember(Strin g string, IWorkbenchWindo w window) {
// TODO Auto-generated constructor stub

super(string);
this.window=win dow;

setId(ICommandI ds.CMD_OPEN_MES SAGE);
// Associate the action with a pre-defined command, to allow key bindings.
setActionDefini tionId(ICommand Ids.CMD_OPEN_ME SSAGE);

}

public void run() {

addmemdialog d=new addmemdialog(wi ndow);
d.open();

}

}

Class addmemdialog:

import org.eclipse.jfa ce.dialogs.Mess ageDialog;
import org.eclipse.jfa ce.window.Appli cationWindow;
import org.eclipse.swt .SWT;
import org.eclipse.swt .events.MouseEv ent;
import org.eclipse.swt .events.MouseLi stener;
import org.eclipse.swt .layout.GridLay out;
import org.eclipse.swt .widgets.Button ;
import org.eclipse.swt .widgets.Compos ite;
import org.eclipse.swt .widgets.Contro l;
import org.eclipse.swt .widgets.Displa y;
import org.eclipse.swt .widgets.Label;
import org.eclipse.swt .widgets.Shell;
import org.eclipse.swt .widgets.Text;
import org.eclipse.ui. IWorkbenchWindo w;

public class addmemdialog extends ApplicationWind ow{

public addmemdialog(IW orkbenchWindow window) {
super(window.ge tShell());
// TODO Auto-generated constructor stub
}

@Override
protected void configureShell( Shell shell) {
// TODO Auto-generated method stub
super.configure Shell(shell);
shell.setText(" Adding a Member");
}

public void run(){
// TODO Auto-generated method stub
setBlockOnOpen( true);
open();
Display.getCurr ent().dispose() ;
}

protected Control createContents( Composite parent){

final Composite composite1 = new Composite(paren t,SWT.BORDER);
composite1.setB ounds(10,10,270 ,250);
composite1.setL ayout(new GridLayout(2,tr ue));
Label ID = new Label(composite 1,SWT.NONE);
ID.setText("Use r ID:");
final Text tID=new Text(composite1 ,SWT.BORDER);
tID.setTextLimi t(30);
Label name=new Label(composite 1,SWT.NONE);
name.setText("U ser name:");
final Text tname=new Text(composite1 ,SWT.BORDER);
tname.setTextLi mit(30);
Label pwd=new Label(composite 1,SWT.NONE);
pwd.setText("Pa ssword:");
final Text tpwd=new Text(composite1 ,SWT.BORDER);
tpwd.setEchoCha r('*');
tpwd.setTextLim it(10);
Label cpwd=new Label(composite 1,SWT.NONE);
cpwd.setText("C onfirm Password:");
final Text tcpwd=new Text(composite1 ,SWT.BORDER);
tcpwd.setEchoCh ar('*');
tcpwd.setTextLi mit(10);
Label dno=new Label(composite 1,SWT.NONE);
dno.setText("Do or number:");
final Text tdno=new Text(composite1 ,SWT.BORDER);
tdno.setTextLim it(30);
Label loc=new Label(composite 1,SWT.NONE);
loc.setText("Lo cality:");
final Text tloc=new Text(composite1 ,SWT.BORDER);
tloc.setTextLim it(30);
Label city=new Label(composite 1,SWT.NONE);
city.setText("C ity:");
final Text tcity=new Text(composite1 ,SWT.BORDER);
tcity.setTextLi mit(30);
Label pin=new Label(composite 1,SWT.NONE);
pin.setText("Pi ncode:");
final Text tpin=new Text(composite1 ,SWT.BORDER);
tpin.setTextLim it(30);
Label state=new Label(composite 1,SWT.NONE);
state.setText(" State:");
final Text tstate=new Text(composite1 ,SWT.BORDER);
tstate.setTextL imit(30);
Label phno=new Label(composite 1,SWT.NONE);
phno.setText("P hone Number:");
final Text tphno=new Text(composite1 ,SWT.BORDER);
tphno.setTextLi mit(30);
Label dtj=new Label(composite 1,SWT.NONE);
dtj.setText("Da te of joining:");
final Text tdtj=new Text(composite1 ,SWT.BORDER);
tdtj.setTextLim it(30);

Button btnsubmit=new Button(composit e1,SWT.PUSH);
btnsubmit.setTe xt("Submit");
Button btncancel=new Button(composit e1,SWT.PUSH);
btncancel.setTe xt("Cancel");

btnsubmit.addMo useListener(new MouseListener() {

public void mouseDoubleClic k(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mouseDown(Mouse Event e){
// TODO Auto-generated method stub
if (tID.getText()= ="" || tname.getText() =="" || tpwd.getText()= ="" || tcpwd.getText() =="" || tdno.getText()= ="" || tloc.getText()= ="" || tcity.getText() =="" || tpin.getText()= ="" || tstate.getText( )=="" || tphno.getText() =="" || tdtj.getText()= =""){
MessageDialog.o penInformation( composite1.getS hell(), "Informatio n", "You have to enter all the fields");
}
else if(!tpwd.getTex t().equals(tcpw d.getText())){
MessageDialog.o penInformation( composite1.getS hell(), "Informatio n", "Your password and confirm password fields are not matched");
}
else
{
MessageDialog.o penInformation( composite1.getS hell(), "User Info", "Your account has been registered");
}

}

public void mouseUp(MouseEv ent e) {
// TODO Auto-generated method stub

}

});

btncancel.addMo useListener(new MouseListener() {

public void mouseDoubleClic k(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mouseDown(Mouse Event e) {
// TODO Auto-generated method stub

tID.setText("") ;
tname.setText(" ");
tpwd.setText("" );
tcpwd.setText(" ");
tdno.setText("" );
tloc.setText("" );
tcity.setText(" ");
tpin.setText("" );
tstate.setText( "");
tphno.setText(" ");
tdtj.setText("" );

}

public void mouseUp(MouseEv ent e) {
// TODO Auto-generated method stub

}

});

return parent;

}

}


Here i have created menu File->Member->Addmember and when i click the items which i have specified appears on the screen such as label,text,butt on controls etc...

But when i click the submit button the mouse down procedure invokes and the validation code which i have specified executes.

Also i want the details to be updated in mysql database. Plaese send me the connection procedure....

Please help me....
Oct 1 '07 #1
16 10748
JosAH
11,448 Recognized Expert MVP
if (tID.getText()= ="" || tname.getText() =="" || tpwd.getText()= ="" || tcpwd.getText() =="" || tdno.getText()= ="" || tloc.getText()= ="" || tcity.getText() =="" || tpin.getText()= ="" || tstate.getText( )=="" || tphno.getText() =="" || tdtj.getText()= =""){

[ ... ]

Also i want the details to be updated in mysql database. Plaese send me the connection procedure....

Please help me....
You can't compary strings like that; use the String.equals() method instead or
in this particular case you can check the String.length() .

Connecting to your database is the same as it was in your previous two posts.

kind regards,

Jos
Oct 1 '07 #2
Ananthu
87 New Member
Hi

I want to use those connectivity codings in mouse down procedure. But i can't use public static void main(String args[]) throws Exception, in this RCP application. Also i want to use throws Exception. What can i do? I want these connectivity codings to be worked when i click the submit button.

Please help me...
Oct 1 '07 #3
JosAH
11,448 Recognized Expert MVP
Hi

I want to use those connectivity codings in mouse down procedure. But i can't use public static void main(String args[]) throws Exception, in this RCP application. Also i want to use throws Exception. What can i do? I want these connectivity codings to be worked when i click the submit button.

Please help me...
Please rephrase your question; all I can see now is that it is certainly *not* about
MySQL connectivity. (btw, use those [ code ] ... [ /code ] tags when you post
code and also don't post *all* of your code all the time).

kind regards,

Jos
Oct 1 '07 #4
Ananthu
87 New Member
Hi

Sorry for posting all the codes. Can you please send me the example code for connecting mysql server with Eclipse in RCP application. I dont know how to do this.

Since RCP application doesn't use public static void main(String args[ ]) method, i dont know how to include the connectivity codings as shown below,

Connectivity Code to mysql server:

import java.sql.Connec tion;
import java.sql.Driver Manager;
import java.sql.Result Set;
import java.sql.Statem ent;

public class MysqlConnect {

public static void main(String[] args)throws Exception{
System.out.prin tln("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql ://localhost:3309/";
String dbName = "ananthu";
String driver = "com.mysql.jdbc .Driver";
String userName = "root";
String password = "sa";
try {
Class.forName(d river);
conn = DriverManager.g etConnection(ur l+dbName,userNa me,password);
System.out.prin tln();
System.out.prin tln("Connected to the database");
System.out.prin tln();
Statement stmt = conn.createStat ement();
ResultSet reset = stmt.executeQue ry("select * from customer");
System.out.prin tln("Name\t\tAg e");
System.out.prin tln();
while(reset.nex t()){
//System.out.prin tln(reset.getSt ring(1));
//System.out.prin tln(reset.getSt ring(2));
System.out.prin tln(reset.getSt ring(1)+ "\t\t" + reset.getString (2));
}
conn.close();
System.out.prin tln();
System.out.prin tln("Disconnect ed from database");
} catch (java.lang.Clas sNotFoundExcept ion e) {
e.printStackTra ce();
}
}

}

I want to include these codings in mouse down procedure of my project in RCP application as i have sent in the first post of this topic.

Please help me...
Oct 1 '07 #5
JosAH
11,448 Recognized Expert MVP
Hi

Sorry for posting all the codes. Can you please send me the example code for connecting mysql server with Eclipse in RCP application. I dont know how to do this.

Since RCP application doesn't use public static void main(String args[ ]) method, i dont know how to include the connectivity codings as shown below,
I know nothing about RCP nor SWT; I guess that you have to supply some callback
class or method or implement some interface; that will be the starting point of
your application and somewhere in there you should build a connection with
your database.

kind regards,

Jos
Oct 1 '07 #6
Ananthu
87 New Member
Hi

Ok. I will try.Thanks for your kind guidance. Your cooperation and guidance is good. Carry on...

We will meet in the next discussion...
Oct 1 '07 #7
Ananthu
87 New Member
Hi

I tried to connect RCP in ECLIPSE with mysql server.I have included the connectivity codings in the,
else part of mousedown procedure of submit button.
After getting the inputs in dialog box from user such as userid,password ,age,date of birth etc.. and when i click the submit button, i get the following errors,

Errors:

java.lang.Class NotFoundExcepti on: com.mysql.jdbc. Driver
at java.lang.Class Loader.findClas s(Unknown Source)
at java.lang.Class Loader.loadClas s(Unknown Source)
at java.lang.Class Loader.loadClas s(Unknown Source)
at org.eclipse.osg i.framework.int ernal.core.Bund leLoader.findCl assInternal(Bun dleLoader.java: 429)
at org.eclipse.osg i.framework.int ernal.core.Bund leLoader.findCl ass(BundleLoade r.java:369)
at org.eclipse.osg i.framework.int ernal.core.Bund leLoader.findCl ass(BundleLoade r.java:357)
at org.eclipse.osg i.internal.base adaptor.Default ClassLoader.loa dClass(DefaultC lassLoader.java :83)
at java.lang.Class Loader.loadClas s(Unknown Source)
at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)
at java.lang.Class .forName0(Nativ e Method)
at java.lang.Class .forName(Unknow n Source)
at rcpexample1.add memdialog$1.mou seDown(addmemdi alog.java:129)
at org.eclipse.swt .widgets.TypedL istener.handleE vent(TypedListe ner.java:178)
at org.eclipse.swt .widgets.EventT able.sendEvent( EventTable.java :66)
at org.eclipse.swt .widgets.Widget .sendEvent(Widg et.java:938)
at org.eclipse.swt .widgets.Displa y.runDeferredEv ents(Display.ja va:3682)
at org.eclipse.swt .widgets.Displa y.readAndDispat ch(Display.java :3293)
at org.eclipse.ui. internal.Workbe nch.runEventLoo p(Workbench.jav a:2389)
at org.eclipse.ui. internal.Workbe nch.runUI(Workb ench.java:2353)
at org.eclipse.ui. internal.Workbe nch.access$4(Wo rkbench.java:22 19)
at org.eclipse.ui. internal.Workbe nch$4.run(Workb ench.java:466)
at org.eclipse.cor e.databinding.o bservable.Realm .runWithDefault (Realm.java:289 )
at org.eclipse.ui. internal.Workbe nch.createAndRu nWorkbench(Work bench.java:461)
at org.eclipse.ui. PlatformUI.crea teAndRunWorkben ch(PlatformUI.j ava:149)
at rcpexample1.App lication.start( Application.jav a:21)
at org.eclipse.equ inox.internal.a pp.EclipseAppHa ndle.run(Eclips eAppHandle.java :153)
at org.eclipse.cor e.runtime.inter nal.adaptor.Ecl ipseAppLauncher .runApplication (EclipseAppLaun cher.java:106)
at org.eclipse.cor e.runtime.inter nal.adaptor.Ecl ipseAppLauncher .start(EclipseA ppLauncher.java :76)
at org.eclipse.cor e.runtime.adapt or.EclipseStart er.run(EclipseS tarter.java:363 )
at org.eclipse.cor e.runtime.adapt or.EclipseStart er.run(EclipseS tarter.java:176 )
at sun.reflect.Nat iveMethodAccess orImpl.invoke0( Native Method)
at sun.reflect.Nat iveMethodAccess orImpl.invoke(U nknown Source)
at sun.reflect.Del egatingMethodAc cessorImpl.invo ke(Unknown Source)
at java.lang.refle ct.Method.invok e(Unknown Source)
at org.eclipse.equ inox.launcher.M ain.invokeFrame work(Main.java: 504)
at org.eclipse.equ inox.launcher.M ain.basicRun(Ma in.java:443)
at org.eclipse.equ inox.launcher.M ain.run(Main.ja va:1169)
at org.eclipse.equ inox.launcher.M ain.main(Main.j ava:1144)


I have included the external jar file of mysql driver in the project in the java bulid path. Please can you send the solution for me?
Oct 1 '07 #8
JosAH
11,448 Recognized Expert MVP
java.lang.Class NotFoundExcepti on: com.mysql.jdbc. Driver

[ ... ]

I have included the external jar file of mysql driver in the project in the java bulid path. Please can you send the solution for me?
This is the same classpath issue again: the jvm simply can't find that class; you
must've made a mistake somewhere; all you have to do is check it all and fix it.
(typo? set the buildpath in another project mayhap?)

kind regards,

Jos
Oct 1 '07 #9
Ananthu
87 New Member
Hi

I have added the jar file of mysql driver in this project in the java build path. But my project is a plug-in project which is RCP application. Then how can i add the jar file in this type of application.

Same errors which i have specified continue to appear in the console window.

What can i do?

Please give me the suitable procedure so that i can complete my project...

Please help me...I am too tired...
Oct 1 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

20
4785
by: Mr Dygi | last post by:
Hi, PHP 4.3.4 installed manually from package *.zip and Apache 2. I have a problem with this simple code: <?php $link = mysql_connect("127.0.0.1","","") or die("Could not connect: " . mysql_error()); echo "Connected successfully"; mysql_close($link);
1
4645
by: pratchaya | last post by:
What the best language code to connect MySQL --> C , C++ , php,VB,Delphi ? about ---- Speed ---- Stable ---- Security Can anyone compare C , C++ , php4,php5 ,vb ,delphi to connect to MySQL ? I need to know how about c++ .
16
27885
by: MLH | last post by:
Using MS Access, I have attached to MySQL servers in other states and other countries on the other side of my router. But when I use the MySQL ODBC driver 3.51 to connect to a MySQL server on my own LAN, the driver tells me it cannot make the connection. Here are the ODBC driver connection parms: Data Source Name: (free field - name my "my...
2
10065
by: Default User | last post by:
Hi there. I have a few newbie questions. My employer has chosen to use IBM WebSphere Application Server to deploy apps on. As one of my first steps in learning Java/J2EE I need to choose and IDE. Some of the questions I can't figure out are: > Since WSAD (WebSphere Application Developer Studio) is very expensive but based off Eclipse, is it...
3
2093
by: frustratedcoder | last post by:
I have installed apache, php5 and mysql on my laptop. I write my code in eclipse and when I test it inside eclipse, the mysql database connection is working, I can execute the script inside eclipse. But when I put that same script into my htdocs on the apache server running on the same laptop and access it using my browser, I get a "Call to...
5
4557
by: news.telia.net | last post by:
Hi! I have a question. I have installed php and mysql on an apache-server on windows and I can't connect to the server. I tried to create a database (since I am trying to learn howto). My manual said I should write this at the shell: c:\mysql\bin>mysqladmin -u root creare mindb I did this and got this error:
3
2199
by: cubano | last post by:
Hi there: I need URGENT help about this .. I wrote a program application for windows which can add and delete data from this application, it working fine with my own MySQL install on the same windows OS.. Now I try to change the connection this dayabase to the server whihc runnign under linux, and create the same database, same user and...
3
6754
by: ravit | last post by:
Hello All, I am trying to execute an application that is developed using eclipse libraries. Jface, SWT , etc. While I execute the application , i have received an exception which I am unable to trace it. TextViewer.setSelection(100,true); is the statement whre it araised. TextViewer is org.eclipse.jface.text.SourceViewer object.
10
5485
nathj
by: nathj | last post by:
Hi there, This thread is very similar to an earlier thread but I didn't want to hijack a thread. The issue is this. I have a mysql database on my local machine, I have installed the driver for Java and MySQL and using Eclipse I can connect to the database and see the tables etc. What I want to do is have a class that defines how to...
0
7820
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8258
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7835
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6486
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5325
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3777
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2255
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.