java & mysql - how to bind jtable from mysql database in java netbeans

java & mysql - how to bind jtable from mysql database in java netbeans

java & mysql - how to Popualte jtable from mysql database in Java netbeans

__________________________________________________________________________

In This Java Code We Will See How To Populate A JTable From Mysql Database  In Java Programming Language.



Project Source Code:

package JavaDB_001;
import java.awt.BorderLayout;
import javax.swing.*;
import java.sql.*;
import java.util.Vector;

public class Test{
public static void main(String[] args){
   Connection con = null;
   Statement st = null;
   ResultSet rs = null;
   String s;

//connect your app to mysql database
   try{
       con = DriverManager.getConnection("jdbc:mysql://localhost/test_db","root","");
       st = con.createStatement();
       s = "select * from users";
       rs = st.executeQuery(s);
       ResultSetMetaData rsmt = rs.getMetaData();
       int c = rsmt.getColumnCount();
       Vector column = new Vector(c);
       for(int i = 1; i <= c; i++)
       {
           column.add(rsmt.getColumnName(i));
       }
       Vector data = new Vector();
       Vector row = new Vector();
       while(rs.next())
       {
           row = new Vector(c);
           for(int i = 1; i <= c; i++){
               row.add(rs.getString(i));
           }
           data.add(row);
       }
       JFrame frame = new JFrame();
       frame.setSize(500,120);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        JTable table = new JTable(data,column);
        JScrollPane jsp = new JScrollPane(table);
        panel.setLayout(new BorderLayout());
        panel.add(jsp,BorderLayout.CENTER);
        frame.setContentPane(panel);
        frame.setVisible(true);
               
               
   }catch(Exception e){
       JOptionPane.showMessageDialog(null, "ERROR");
   }finally{
       try{
       st.close();
       rs.close();
       con.close();
       }catch(Exception e){
           JOptionPane.showMessageDialog(null, "ERROR CLOSE");
       }
   }
      
  }
}
You can also Fill JTable From mySQL DataBase Using ArrayList
Java and MySQL - How To Connect Java To MySQL And Dsiplay Data In NetBeans

Java and MySQL - How To Connect Java To MySQL And Dsiplay Data In NetBeans

Java and MySQL - How To Connect Java To MySQL And Dsiplay Data In NetBeans

__________________________________________________________________________

In This Java Tutorial We Will See How To Connect Java To MySQL DataBase Using NetBeans.




Project Source Code:


downloads connector:  http://dev.mysql.com/downloads/connector/j

package javadb_001;
import java.sql.*;

public class JavaDB_001 {

    public static void main(String[] args) {
     
     try{
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test_db","root","");
         Statement st = con.createStatement();
         ResultSet rs = st.executeQuery("select * from users");
         while(rs.next())
         {
             System.out.println(rs.getString(1));
             System.out.println(rs.getString(2));
             System.out.println(rs.getString(3));
             System.out.println(rs.getString(4));
             System.out.println("----------------------");
         }
         
     }catch(Exception e)
     {
         System.out.println(e.getMessage());
     }
    }
}

C# and MySQL - How To Connect C# To MySQL And Display Data

C# and MySQL - How To Connect C# To MySQL And Display Data

                                                                                                                                         

In This C# Tutorials We Will See How To Connect CSharp  To MySQL DataBase .

                                              
                                                        1 - Connect To MySQL 



2 - Connect And Show Data In Datagridview

Project Source Code:

1 - Connect

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Csharp_And_MySQL
{
    public partial class
Csharp_Connect_To_MySQL_Database : Form
    {
        public
Csharp_Connect_To_MySQL_Database()
        {
            InitializeComponent();
        }
        MySqlConnection connection;
        private void
Csharp_Connect_To_MySQL_Database_Load(object sender, EventArgs e)
        {
           
try
            {
                connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=");
                connection.Open();
                if(connection.State == ConnectionState.Open)
                {
                    label1.Text = "Connected";
                    label1.ForeColor = Color.Green;
                }
                else
                {
                    label1.Text = "Not Connected";
                    label1.ForeColor = Color.Red;
                }
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
                label1.Text = "Not Connected";
                label1.ForeColor = Color.Red;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (connection.State == ConnectionState.Closed)
            {
                connection.Open();
                label1.Text = "Connected";
                label1.ForeColor = Color.Green;
            }
        }
    }

}


=> OUTPUT :

How To Connect C# To MySQL Database


2 - Connect And Display

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace
Csharp_And_MySQL
{
    public partial class Csharp_Display_Data_From_Mysql_Into_Datagridview : Form
    {
        public Csharp_Display_Data_From_Mysql_Into_Datagridview()
        {
            InitializeComponent();
        }
        private void Csharp_Display_Data_From_Mysql_Into_Datagridview_Load(object sender, EventArgs e)
        {
            
            try
            {
                MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=");
                MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM test_db.users", connection);
                connection.Open();
                DataSet ds = new DataSet();
                adapter.Fill(ds, "users");
                dataGridView1.DataSource = ds.Tables["users"];
                connection.Close();
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }
    }

}


=> OUTPUT :

populate datagridview from mysql database in c#

JAVA - How to set background image in Java for a JFrame

JAVA - How to set background image in Java for a JFrame

How to set background image in Java for a JFrame


__________________________________________________________________________

In This Java Code We Will See How You Can Make A BackGround Image For Your JFrame In Java Using A JLabel Programming Language.

Method 1: image from Desktop.

Source Code: 


package learn;

import java.awt.FlowLayout;

import javax.swing.*;

import java.io.IOException;

import java.io.*;

import javax.imageio.*;

public class Test2 extends JFrame{
    
    public Test2(){
    super("window");
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    try{
        setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("C:\\Users\\samsng\\Documents\\NetBeansProjects\\Learn\\src\\learn\\images\\sparta.jpg")))));
    
    }catch(IOException e)
    {
        e.printStackTrace();
       
    }
    this.setLayout(new FlowLayout());
    this.setResizable(false);
    this.pack();
    this.setVisible(true);
    }
    public static void main(String[] args) {
        Test2 t = new Test2();
    }
}

Method 1: image from Resource.

Step 1: create a new package.
Step 2: add an image to the package.

Source Code: 

package learn;
import javax.swing.*;

public class Test extends JFrame{
    
    public Test(){
    super("window");
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel pan = new JPanel();
    JLabel jlb = new JLabel();
     jlb.setIcon(new ImageIcon(getClass().getResource("images//sparta.jpg")));
     
   pan.add(jlb);

    this.setContentPane(jlb);
    this.setResizable(false);
    this.pack();
    this.setVisible(true);
    }
    public static void main(String[] args) {Test t = new Test();}
}




*Java Courses Java Complete Course
                            Java Swing Course
JAVA - How To Bind Data In JTable In Netbeans

JAVA - How To Bind Data In JTable In Netbeans

JAVA - How To Fill Data In JTable In Java Netbeans.


__________________________________________________________________________

In This Java Code We Will See How To Populate  A  JTable  Using  In   Java   NetBeans Programming Language.

Source Code: 

package javadb_001;

import javax.swing.*;


public class To_JTable extends JFrame  {
    Object row[][] = {{"A","B","C"},{"D","E","F"},{"J","H","I"},{"G","K","L"},
                      {"D","E","F"},{"J","H","I"},{"G","K","L"},
                      {"D","E","F"},{"J","H","I"},{"G","K","L"},
                      {"D","E","F"},{"J","H","I"},{"G","K","L"},
                      {"A","B","C"},{"D","E","F"},{"J","H","I"},{"G","K","L"},
                      {"A","B","C"},{"D","E","F"},{"J","H","I"},{"G","K","L"},
                      };
    Object column[] = {"1","1","3"};
    JTable jt;
    JScrollPane js;
    public Mysql_To_JTable()
    {
       super("Mysql TO JTable");

       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       jt = new JTable(row, column);

       js = new JScrollPane(jt);

       this.setSize(500, 300);

       this.setLocationRelativeTo(null);

       this.add(js);

       this.setVisible(true);
    }

    public static void main(String[] args)
    {
        new To_JTable();
    }
}



*Java Courses Java Complete Course
                            Java Swing Course
How to set background image in Java for a JFrame using a JLabel

How to set background image in Java for a JFrame using a JLabel

How to set background image in Java for a JFrame using a JLabel


__________________________________________________________________________

In This Java Code We Will See How You Can Make A BackGround Image For Your JFrame In Java Using A JLabel Programming Language.

Project Source Code:

package learn;
import java.awt.FlowLayout;
import javax.swing.*;
import java.io.IOException;
import java.io.*;
import javax.imageio.*;

public class Test extends JFrame{
 
    public Test(){
    super("window");
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    try{
        setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("C:\\Users\\samsng\\Documents\\NetBeansProjects\\images\\image.jpg")))));
 
    }catch(IOException e)
    {
        e.printStackTrace();
     
    }
    this.setLayout(new FlowLayout());
    this.setResizable(false);
    this.pack();
    this.setVisible(true);
    }

public static void main(String[] args) {

       Test t = new Test();

    }
}

C# - How To Get Your Address IP Using C#

C# - How To Get Your Address IP Using C#

C# - How To Get Your Address IP Using C#

                                                                                                                                  

In This C# Tutorial We Will See How To Show Your IP Address In A Label Using CSharp Programming Language .


Source Code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;


namespace WindowsFormsApplication1
{
    public partial class Get_Ip_Address : Form
    {
        public Get_Ip_Address()
        {
            InitializeComponent();
        }

        private void Get_Ip_Address_Load(object sender, EventArgs e)
        {

            IPHostEntry iph;
            string myip = "";
            iph = Dns.GetHostEntry(Dns.GetHostName());
            foreach(IPAddress ip in iph.AddressList)
            {
                if(ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    myip = ip.ToString();
                }
            }
            label1.Text = myip.ToString();
        }
    }
}