473,287 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

How to connect mysql with ECLIPSE in RCP application

87
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 ApplicationActionBarAdvisor:

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAct ion;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

private Action addmember;

public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}

protected void makeActions(IWorkbenchWindow window) {

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

}

protected void fillMenuBar(IMenuManager menuBar) {

MenuManager File=new MenuManager("&File",IWorkbenchActionConstants.M_FI LE);
MenuManager Member=new MenuManager("&Member",null);
menuBar.add(File);
File.add(Member);
Member.add(addmember);
}
}

Class Addmember:

import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchWindow;

public class Addmember extends Action {

private IWorkbenchWindow window;
//public static boolean internalCall = false;

//public Addmember(){ };

public Addmember(String string, IWorkbenchWindow window) {
// TODO Auto-generated constructor stub

super(string);
this.window=window;

setId(ICommandIds.CMD_OPEN_MESSAGE);
// Associate the action with a pre-defined command, to allow key bindings.
setActionDefinitionId(ICommandIds.CMD_OPEN_MESSAGE );

}

public void run() {

addmemdialog d=new addmemdialog(window);
d.open();

}

}

Class addmemdialog:

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchWindow;

public class addmemdialog extends ApplicationWindow{

public addmemdialog(IWorkbenchWindow window) {
super(window.getShell());
// TODO Auto-generated constructor stub
}

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

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

protected Control createContents(Composite parent){

final Composite composite1 = new Composite(parent,SWT.BORDER);
composite1.setBounds(10,10,270,250);
composite1.setLayout(new GridLayout(2,true));
Label ID = new Label(composite1,SWT.NONE);
ID.setText("User ID:");
final Text tID=new Text(composite1,SWT.BORDER);
tID.setTextLimit(30);
Label name=new Label(composite1,SWT.NONE);
name.setText("User name:");
final Text tname=new Text(composite1,SWT.BORDER);
tname.setTextLimit(30);
Label pwd=new Label(composite1,SWT.NONE);
pwd.setText("Password:");
final Text tpwd=new Text(composite1,SWT.BORDER);
tpwd.setEchoChar('*');
tpwd.setTextLimit(10);
Label cpwd=new Label(composite1,SWT.NONE);
cpwd.setText("Confirm Password:");
final Text tcpwd=new Text(composite1,SWT.BORDER);
tcpwd.setEchoChar('*');
tcpwd.setTextLimit(10);
Label dno=new Label(composite1,SWT.NONE);
dno.setText("Door number:");
final Text tdno=new Text(composite1,SWT.BORDER);
tdno.setTextLimit(30);
Label loc=new Label(composite1,SWT.NONE);
loc.setText("Locality:");
final Text tloc=new Text(composite1,SWT.BORDER);
tloc.setTextLimit(30);
Label city=new Label(composite1,SWT.NONE);
city.setText("City:");
final Text tcity=new Text(composite1,SWT.BORDER);
tcity.setTextLimit(30);
Label pin=new Label(composite1,SWT.NONE);
pin.setText("Pincode:");
final Text tpin=new Text(composite1,SWT.BORDER);
tpin.setTextLimit(30);
Label state=new Label(composite1,SWT.NONE);
state.setText("State:");
final Text tstate=new Text(composite1,SWT.BORDER);
tstate.setTextLimit(30);
Label phno=new Label(composite1,SWT.NONE);
phno.setText("Phone Number:");
final Text tphno=new Text(composite1,SWT.BORDER);
tphno.setTextLimit(30);
Label dtj=new Label(composite1,SWT.NONE);
dtj.setText("Date of joining:");
final Text tdtj=new Text(composite1,SWT.BORDER);
tdtj.setTextLimit(30);

Button btnsubmit=new Button(composite1,SWT.PUSH);
btnsubmit.setText("Submit");
Button btncancel=new Button(composite1,SWT.PUSH);
btncancel.setText("Cancel");

btnsubmit.addMouseListener(new MouseListener(){

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

}

public void mouseDown(MouseEvent 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.openInformation(composite1.getShell( ), "Information", "You have to enter all the fields");
}
else if(!tpwd.getText().equals(tcpwd.getText())){
MessageDialog.openInformation(composite1.getShell( ), "Information", "Your password and confirm password fields are not matched");
}
else
{
MessageDialog.openInformation(composite1.getShell( ), "User Info", "Your account has been registered");
}

}

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

}

});

btncancel.addMouseListener(new MouseListener(){

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

}

public void mouseDown(MouseEvent 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(MouseEvent 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,button 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 10725
JosAH
11,448 Expert 8TB
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
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 Expert 8TB
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
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.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class MysqlConnect {

public static void main(String[] args)throws Exception{
System.out.println("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(driver);
conn = DriverManager.getConnection(url+dbName,userName,pa ssword);
System.out.println();
System.out.println("Connected to the database");
System.out.println();
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from customer");
System.out.println("Name\t\tAge");
System.out.println();
while(reset.next()){
//System.out.println(reset.getString(1));
//System.out.println(reset.getString(2));
System.out.println(reset.getString(1)+ "\t\t" + reset.getString(2));
}
conn.close();
System.out.println();
System.out.println("Disconnected from database");
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
}
}

}

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 Expert 8TB
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
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
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.ClassNotFoundException: com.mysql.jdbc.Driver
at java.lang.ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClassInternal(BundleLoader.java:429)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:369)
at org.eclipse.osgi.framework.internal.core.BundleLoa der.findClass(BundleLoader.java:357)
at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.loadClass(DefaultClassLoader.java:83)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at rcpexample1.addmemdialog$1.mouseDown(addmemdialog. java:129)
at org.eclipse.swt.widgets.TypedListener.handleEvent( TypedListener.java:178)
at org.eclipse.swt.widgets.EventTable.sendEvent(Event Table.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.ja va:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents( Display.java:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Di splay.java:3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Wor kbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench. java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workben ch.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench. java:466)
at org.eclipse.core.databinding.observable.Realm.runW ithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWork bench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(Pl atformUI.java:149)
at rcpexample1.Application.start(Application.java:21)
at org.eclipse.equinox.internal.app.EclipseAppHandle. run(EclipseAppHandle.java:153)
at org.eclipse.core.runtime.internal.adaptor.EclipseA ppLauncher.runApplication(EclipseAppLauncher.java: 106)
at org.eclipse.core.runtime.internal.adaptor.EclipseA ppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.ru n(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.ru n(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework( Main.java:504)
at org.eclipse.equinox.launcher.Main.basicRun(Main.ja va:443)
at org.eclipse.equinox.launcher.Main.run(Main.java:11 69)
at org.eclipse.equinox.launcher.Main.main(Main.java:1 144)


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 Expert 8TB
java.lang.ClassNotFoundException: 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
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
Ananthu
87
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 in the previous post 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 #11
RedSon
5,000 Expert 4TB
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 in the previous post 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...
I would suggest asking a knowledgeable adult or instructor for help.
Jul 2 '08 #12
r035198x
13,262 8TB
Hi

I have added the jar file of mysql driver in this project in the java build path. ...

Then how can i add the jar file in this type of application.
So have you or have you not added that jar?
<confused>
Jul 2 '08 #13
JosAH
11,448 Expert 8TB
Not that it matters much but this thread has been dead for nine months ...

kind regards,

Jos
Jul 2 '08 #14
RedSon
5,000 Expert 4TB
Not that it matters much but this thread has been dead for nine months ...

kind regards,

Jos
The user is still active though.
Jul 2 '08 #15
JosAH
11,448 Expert 8TB
The user is still active though.
So am I but I'm not desperately seeking for my pacifier anymore ;-)

kind regards,

Jos
Jul 2 '08 #16
Did you get it resolved?
Mar 7 '16 #17

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

Similar topics

20
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: " ....
1
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...
16
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...
2
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....
3
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...
5
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...
3
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...
3
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...
10
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.