how to connect mysql from gui?

how to connect mysql from gui?

i am unable to connet to mysql server from my projet that is gui for mysql...can anyone help me in this...its urgent? i have to connet to mysql from gui..

View Answers

November 29, 2010 at 10:47 AM

Hi Friend,

Try the following code:

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
class  Retrieve{

    public static void main(String[] args){
    JFrame f=new JFrame();
    JLabel label1=new JLabel("Name: ");
    JLabel label2=new JLabel("Address: ");
    JTextField text1=new JTextField(20);
    JTextField text2=new JTextField(20);
    try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from data where id=1");
           String name="",address="";
           if(rs.next()){
               name=rs.getString("name");
               address=rs.getString("address");
           }
           text1.setText(name);
           text2.setText(address);
          }
        catch(Exception e){
        }
        JPanel p=new JPanel(new GridLayout(2,2));
        p.add(label1);
        p.add(text1);
        p.add(label2);
        p.add(text2);
        f.add(p);
        f.setVisible(true);
        f.pack();
    }
}

Thanks









Related Tutorials/Questions & Answers:
how to connect mysql from gui?
How to connect to MySQL from command prompt?
Advertisements
How to connect mysql with jsp
How to connect to MySQL in JSP?
How to connect to MySql Database from Servlet?
how to connect mysql with JDBC - JDBC
how to connect mySql drivers into eclipse(configuration)?
how to connect to database in php using mysql
Mysql connect
ModuleNotFoundError: No module named 'guio'
Connect JSP with mysql
how to connect jsp to mysql - Java Beginners
how to connect j2me program with mysql using servlet?
mysql_connect arguments
ModuleNotFoundError: No module named 'guiu-english'
How to delete data from MySQL?
Connect JSP with mysql
ModuleNotFoundError: No module named 'FarPy-GUIE'
ModuleNotFoundError: No module named 'upt-guix'
ModuleNotFoundError: No module named 'FarPy-GUIE'
connect to the database from JSP
ModuleNotFoundError: No module named 'connect-mysql'
ModuleNotFoundError: No module named 'connect-mysql'
How to update mysql from 5.1 to 5.5
how to fetch image from mysql using jsp
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code - JDBC
ModuleNotFoundError: No module named 'guid'
ModuleNotFoundError: No module named 'guix-import-debian'
not able to connect to mysql using.. jdbc
How to retrieve image from mysql database in JSP?
How to access (MySQL)database from J2ME?
How to connect
How to make a connection from javaME with MySQL - SQL
need help....how to connect and disconnect multiple databases(databases created in mysql) using java and my sql
how to retrive the particular data from database in php with mysql?
How to make a connection from javaME with MySQL - SQL
ModuleNotFoundError: No module named 'secv-guis'
ModuleNotFoundError: No module named 'secv-guis'
ModuleNotFoundError: No module named 'new-guid'
ModuleNotFoundError: No module named 'django-guid'
ModuleNotFoundError: No module named 'generate-GUID'
ModuleNotFoundError: No module named 'guid-core'
ModuleNotFoundError: No module named 'guid-tool'
error call to undefined function mysql_connect
how to insert and retrieve an image from mysql using java - Java Beginners
how to connect webcam in html
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql
connect ftp from java program

Ads