Results 1 to 1 of 1
Thread: SWT and MYSQL
- 07-18-2010, 01:49 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 71
- Rep Power
- 0
SWT and MYSQL
hi guys.. please help me how to connect my swt codes to mysql... :confused:
here's my code:
Java Code:package webportalcms; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.*; public class InstructorModule { public InstructorModule(Display display,Shell shell){ final Shell Imodule = new Shell(shell,SWT.APPLICATION_MODAL); Imodule.setBounds(50,100,900,500); Imodule.open(); Label lblInstructor = new Label(Imodule,SWT.NONE); lblInstructor.setText("ADD NEW INSTRUCTOR"); lblInstructor.setBounds(175,15,250,30); //TO CHANGE THE FONT SIZE OF THE LABEL FontData[] fD = lblInstructor.getFont().getFontData(); fD[0].setHeight(16); lblInstructor.setFont( new Font(display,fD[0])); Group grpInstructor = new Group(Imodule,SWT.SHADOW_ETCHED_OUT); grpInstructor.setText("Instructor's Information"); grpInstructor.setBounds(175,60,650,400); /* FOR LABEL */ Label idInstructor = new Label(grpInstructor,SWT.NONE); idInstructor.setText("Instructor ID:"); idInstructor.setBounds(40,50,70,30); Label lastName = new Label(grpInstructor,SWT.NONE); lastName.setText("Last Name:"); lastName.setBounds(40,90,70,30); Label firstName = new Label(grpInstructor,SWT.NONE); firstName.setText("First Name:"); firstName.setBounds(270,90,70,30); Label middleInitial = new Label(grpInstructor,SWT.NONE); middleInitial.setText("Middle Initial:"); middleInitial.setBounds(490,90,70,30); Label department = new Label(grpInstructor,SWT.NONE); department.setText("Department:"); department.setBounds(40,130,70,30); Label position = new Label(grpInstructor,SWT.NONE); position.setText("Position:"); position.setBounds(270,130,70,30); Label email = new Label(grpInstructor,SWT.NONE); email.setText("Email Address:"); email.setBounds(40,225,70,30); Label password = new Label(grpInstructor,SWT.NONE); password.setText("Password:"); password.setBounds(40,260,70,30); final Text txtID = new Text(grpInstructor,SWT.BORDER); txtID.setBounds(110, 45, 120, 23); final Text txtlastName = new Text(grpInstructor,SWT.BORDER); txtlastName.setBounds(110, 85, 120, 23); final Text txtfirstName = new Text(grpInstructor,SWT.BORDER); txtfirstName.setBounds(340, 85, 120, 23); final Text txtMI = new Text(grpInstructor,SWT.BORDER); txtMI.setBounds(560, 85, 30, 23); final Combo combodept = new Combo(grpInstructor,SWT.READ_ONLY); String item[] = {"IT","GE"}; combodept.setItems(item); combodept.setBounds(110,125,120,23); final Text txtposition = new Text(grpInstructor,SWT.BORDER); txtposition.setBounds(340,125,120,23); final Text txtead = new Text(grpInstructor,SWT.BORDER); txtead.setBounds(110,220,200,23); final Text txtpassword = new Text(grpInstructor,SWT.BORDER); txtpassword.setBounds(110,255,120,23); Button btnOpen = new Button(Imodule,SWT.PUSH); btnOpen.setBounds(20,210,90,80); btnOpen.setText("Open"); btnOpen.addSelectionListener(new SelectionAdapter(){ public void widgetSelected (SelectionEvent e){ InstructorView view = new InstructorView(Imodule); } }); Button btnSave = new Button(Imodule,SWT.PUSH); btnSave.setBounds(20,300,90,80); btnSave.setText("Save"); btnSave.addSelectionListener(new SelectionAdapter(){ public void widgetSelected (SelectionEvent e){ [B] try{ Class.forName("com.mysql.jdbc.Driver"); Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/sti_taft","root",""); System.out.println("Connecting succesfully"); Statement statement = connect.createStatement(); ResultSet resultSet = statement.executeQuery("Insert Into tblinstructor values('"+txtID.getText()+"')," + "'"+txtlastName.getText()+"','"+txtfirstName.getText()+"','"+txtMI.getText()+"'," + "'"+combodept.getText()+"','"+txtposition.getText()+"','"+txtead.getText()+"'," + "'"+txtpassword.getText()+"' "); }catch(Exception a){ System.out.println("Cannot connect to database server"); } } });[/B] Button btnClose = new Button(Imodule,SWT.PUSH); btnClose.setBounds(20,390,90,80); btnClose.setText("Close"); btnClose.addSelectionListener(new SelectionAdapter(){ public void widgetSelected (SelectionEvent e){ Imodule.close(); } }); } }
:cool:
Similar Threads
-
mysql help
By messi_fcb in forum JDBCReplies: 1Last Post: 03-27-2010, 10:56 PM -
SWT and mysql
By ashin in forum SWT / JFaceReplies: 4Last Post: 07-09-2009, 05:46 AM -
MySQL/JDBC Mysql query output
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 02-13-2009, 02:57 AM -
mySQL HELP!!!
By ace84 in forum New To JavaReplies: 0Last Post: 04-19-2008, 11:39 PM -
Mysql Help
By Sumendra Maharjan in forum JDBCReplies: 1Last Post: 08-08-2007, 02:19 AM
Bookmarks