java-mysql

java-mysql

how i retrive all the values of a table in mysql to java forms or java table

View Answers

November 24, 2010 at 12:04 PM

Hi Friend,

We are providing you the codes to retrieve database data into form and table.

1)In Form:

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();
    }
}

2)In Jtable:

import java.io.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;

class JTableDatabase extends JFrame{
    ResultSet rs;
    JTableDatabase(){
    final Vector columnNames = new Vector();
        final Vector data = new Vector();
      JPanel panel=new JPanel();
      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");
    ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int i = 1; i <= columns; i++) {
columnNames.addElement( md.getColumnName(i) );
}
while (rs.next()) {
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++) {
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
}
catch(Exception e){}
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
panel.add(scrollPane);
add(panel);
}
 public static void main(String arg[])
  {
    try
    {
    JTableDatabase frame=new JTableDatabase();
    frame.setSize(450,200);
    frame.setVisible(true);
    }
  catch(Exception e)
    {}
  }
}

Thanks









Related Tutorials/Questions & Answers:
Java-mysql coding - Java Beginners
Java-mysql coding  Dear Sir, Suppose I have Employee master file in Mysql table format & I want to update that file thru JavaSwing Input format... employee joins, his master details are putted in Java-Swing Form, how I can insert
website creation using java and mysql - Java Beginners
website creation using java and mysql  i am going to create a website for some company using java and mySql... i dont know the procedure to create a website.can anybody give me the steps what i have to follow
Advertisements
java-mysql
java-mysql  how i retrive all the values of a table in mysql to java forms or java table
java with mysql
java with mysql  Hi, Here is my code: import java.awt.*; import...=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","root...` VARCHAR(20) NOT NULL)"; con=DriverManager.getConnection("jdbc:mysql
Java and Mysql
Java and Mysql  Sir, I want to connect my java program with mysql server (mysql server is situated on another windows machine ) ??? ???? ?????   Put mysql jar file in your jdk lib and set the classpath. After
java & mysql
java & mysql  I wrote the code as shown below, i am getting the error... to your MySQL server version for the right syntax to use near '' at line 1" my...("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql
java & mysql
java & mysql  I wrote the code as shown below, i am getting the error... to your MySQL server version for the right syntax to use near '' at line 1" my...("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql
java & mysql
java & mysql  I wrote the code as shown below, i am getting the error... to your MySQL server version for the right syntax to use near '' at line 1" my...("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql
java & mysql
java & mysql  I wrote the code as shown below, i am getting the error... to your MySQL server version for the right syntax to use near '' at line 1" my...("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql
java & mysql
java & mysql  I wrote the code as shown below, i am getting the error... to your MySQL server version for the right syntax to use near '' at line 1" my...("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql
Java and MySQL
Java and MySQL   I am doing a project on an accounting system. I need to know to things: How do I write reports using information in an MySQL database . How get multiple MySQL database rows and assign them to variables r
How to select Data Between Two dates in Java, MySQL
How to select Data Between Two dates in Java, MySQL  How to select Data Between Two dates in Java, MySQL? Thanks in advance.   http://www.v7n.com/forums/coding-forum/294668-how-select-data-between-two-dates-php
Maven Repository/Dependency: com.github.testcontainers.testcontainers-java | mysql
Maven Repository/Dependency of Group ID com.github.testcontainers.testcontainers-java and Artifact ID mysql. Latest version of com.github.testcontainers.testcontainers-java:mysql dependencies. # Version
JAVA & MYSQL - JDBC
JAVA & MYSQL  How can we take backup of MySQL 5.0 database by using...;Hi Friend, Please visit the following page for working example of MySQL backup. This may help you in solving your problem. www.roseindia.net/mysql/mysql
Creating an Encyclopedia using Java & mySQL 5 - Java Beginners
Creating an Encyclopedia using Java & mySQL 5  Dear Editor, I'm very impressed of your Java tutorial website. I'm take up advance JAva... as i need to applied the Java skill to my company. I got a problem of doing
Java Mysql Connection Example
Java Mysql Connection Example We are going to discus how to connect  MySQL in java. We have been provide some classes and API with which we will make... the MySQL database with java prommining. Classes, interfaces and methods
How To Store Image Into MySQL Using Java
How To Store Image Into MySQL Using Java In this section we will discuss about how to store an image into the database using Java and MySQL. This example... you about how to store image into database using Java. We will use the MySQL
question
question  Please give me a code for search engine using java and mysql
question
question  Good Afternoon Sir, Please give me a client Server Socket programming using jsp and java with mysql connection
source code - JDBC
source code  give me a source code to connect from java to mysql that can run on eclipsed i am using mysql-essential-5.0.41-win32_1. also give procedure how can i connect from eclipsed to mysql-essential-5.0.41-win32_1. thanks
question
all attendances marked )-using JPannel+java + mysql
create archive file on local disk in oracle 9i
create archive file on local disk in oracle 9i  how to create archive file on local disk and insert it in the oracle 9i database by java and MySQL. plz send to whole description all about this urgently. Thanks
MySql ClassNotFoundException - JDBC
install in linux any software making connection between java and MySQL. Or how can i...MySql ClassNotFoundException  Dear sir, i am working in Linux platform with MySQL database , actually i finished all installation in MySQL
JDBC - Java Beginners
JDBC   To connect java with mysql database i used the proper class... as "class not found error". Is there any steps to connect mysql with java... where your mysql connector jar file available thats allj ar file name = mysql
JDBC CONNECTIVITY
file in environment variable.   Java Mysql connectivity Other JDBC...JDBC CONNECTIVITY  How do i connect my database to java. I have the connector file and i place it in lib of jdk folder and installed the jdbc driver
mysql table extract
mysql table extract  Hello friends!! I am a trainee. I am learning connectivity of java with MYSQL. I want to extract table from mysql so that I can access it on another computer. I want to attach mysql table to my java NETBEANS
connecting jsp to mysql - JSP-Servlet
development' project that uses JSP, MySQL and tomcat.i am not able to connect to the mysql database through jsp. After downloading the mysql-connector-java-5.0   One jar file is needed to connect java with mysql data base. That can
question
on Leave Another grid to show the employees who are on leave Using JPannel,java and mysql
Create a counter in mySQL 5 database through Java - SQL
Create a counter in mySQL 5 database through Java  Dear Editor, Thanks for your valuable Java code example for JFileChooser. I had another question regarding Java & mySQL 5 database
regarding java - JDBC
done front end work using swing and AWT concepts of java i am using mysql as back end and i have also configured java with mysql i am using three table in mysql supplier table producer table customer table problem is that how i
JDBC
between java and mysql using JDBC and saves the data into the database. import...) { System.out.println("Inserting values in Mysql database table!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
the connection between java and mysql using JDBC and saves the data into the database...[] args) { System.out.println("Inserting values in Mysql database table!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db
MYSQL Java Connector Library
Where to download the MYSQL Java Connector Library and get the jar file This article discuss 'how to connect Java and MYSQL using MYSQL connector' in Java. The article will give you view on downloading and installing MYSQL Java
Set Data Types by using Prepared Statement
) in the PreparedStatement interface of java.sql package. We know that the data types of MySQL and java... the data to each other Java and MySQL. Mapping between both java and MySQL...) individually according to it's nature that is supported by both java and MySQL. Data
Processing stored procedure in MySQL - SQL
Processing stored procedure in MySQL  Dear All java with mysql developer..... i need to convert my SQL procedure to MySQL database... here is my Stored procedure in SQL.... create or replace procedure INVNAMES (bno
jdbc - Java Beginners
is: Expert:Jagadeesh To connect java with mysql database i used the proper class... error". Is there any steps to connect mysql with java before running. ---Answers Hello friend inside your project set the class path where your mysql connector
Dynamic Website Designing
websites using JSP, PHP, Java and MySQL. We proficiently deal in news website
JDBC CONNECTIVITY
execution finished."""""") what may the problem?   Java Mysql... // File name: Document [1].java /** * This class is generated from template..."); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/abhi
Set byte, short and long data types by using the Prepared Statement
;that the java and MySQL data types could not be same. But mapping is a mechanism... understanding see the mapping between java and MySQL in the following explanation.  Java data type    MySQL data type byte  tinyint
dennis
a web service in SCALA or JAVA, MySql, AND IN SPARK using apprehension (Promise... using a MySQL database and provide within the runnable program the following...: Provide a program in SCALA and SPARK, and also in JAVA and SPARK
Free Big Data Training and Certification
in programming then at least you should learn the basics of Java and MySQL Server... with any of the database management system such as Oracle, MySQL or MSSQL... at: Big Data and Hadoop online training for Java Programmer. Here
Free Big Data Training and Certification
the basics of Java and MySQL Server to start with the Big Data training... such as Oracle, MySQL or MSSQL server is also very helpful in learning Big Data... training for Java Programmer. Here is the outline of topics covers in our

Ads