16
Mar
2019

Connect Java with Database – Using JDBC-ODBC string

Views: 2
0 0
Read Time:3 Minute, 51 Second

Connect Java with Database – Using JDBC-ODBC string. Here is a complied program that how to create connection using java JDBC /ODBC connection string, Complete verified codding for connection of java with MS ACCESS database.

java and ms access connection string. Java connection string to connect with database. how we can connect java program to a database.

Database connection string to connect java program with ms access, MS SQL and SQL Server. How can someone create a program to submit data into database. java programe to enter data into database.

Complete Verified Coding for connect java with database

import java.awt.; import java.awt.event.;
import java.sql.; import javax.swing.;

class kaleem extends Frame implements ActionListener

{
Connection con;
Statement stmt;
ResultSet rs;

JButton bt1,bt2,pic;
            JTextField t1,t2,t3,t4,t5;
            JLabel l1,l2,l3,l4,l5,l6;
ImageIcon img;

kaleem()
{
super(“DataBase”);
setBounds(250,150,600,500);
setBackground(new Color(10,120,149));
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
dispose();
}
});
setLayout(null);

img = new ImageIcon("k.gif");

   bt1=new JButton("Next");
   bt1.setBounds(120,50,100,40);
   bt1.addActionListener(this);
   bt1.setFont(new Font("Monotype Corsiva",Font.BOLD,18));

    l1=new JLabel("ID :");
    l1.setBounds(50,150,120,40);    
    l1.setFont(new Font("Monotype Corsiva",Font.BOLD,20));
    l1.setBackground(new Color(10,12,14));

l1.setForeground(new Color(250,50,250));

   t1=new JTextField("kaleem",30);
   t1.setBounds(150,150,120,40);
   t1.setFont(new Font("Monotype Corsiva",Font.BOLD,20));


    bt2=new JButton("Previous");
    bt2.setBounds(270,50,100,40);
    bt2.addActionListener(this);
    bt2.setFont(new Font("Monotype Corsiva",Font.BOLD,18));

    l2=new JLabel("Name :");
    l2.setBounds(50,200,120,40);
    l2.setFont(new Font("Monotype Corsiva",Font.BOLD,20));

l2.setForeground(new Color(250,50,250));

    t2=new JTextField("MSc I T",30);
    t2.setBounds(150,200,120,40);
    t2.setFont(new Font("Monotype Corsiva",Font.BOLD,20));

    l3=new JLabel("Class :");
    l3.setBounds(50,250,120,40);
    l3.setFont(new Font("Monotype Corsiva",Font.BOLD,20));

l3.setForeground(new Color(250,50,250));

    t3=new JTextField("2804",30);
    t3.setBounds(150,250,120,40);
    t3.setFont(new Font("Monotype Corsiva",Font.BOLD,20));

    l4=new JLabel("Roll No :");
    l4.setBounds(50,300,120,40);
    l4.setFont(new Font("Monotype Corsiva",Font.BOLD,20));

l4.setForeground(new Color(250,50,250));

    t4=new JTextField("Data_Base",30);
    t4.setBounds(150,300,120,40);
    t4.setFont(new Font("Monotype Corsiva",Font.BOLD,20));

t5=new JTextField(“Data_Base”,30);
t5.setBounds(150,350,120,40);
t5.setFont(new Font(“Monotype Corsiva”,Font.BOLD, 20));

    l5=new JLabel("Designed By: M_KALEEM");
l5.setBounds(300,320,250,30);
l5.setForeground(new Color(250,50,250));
    l5.setFont(new Font("Monotype Corsiva",Font.BOLD,22));

l6=new JLabel(“Subject :”);
l6.setBounds(50,350,120,40);
l6.setFont(new Font(“Monotype Corsiva”,Font.BOLD,20));
l6.setBackground(new Color(10,12,14));
l6.setForeground(new Color(250,50,250));

pic=new JButton(img);
pic.setBounds(300,150,130,140);
pic.addActionListener(this);

add(bt1);
add(bt2);
 add(t1);
    add(t2);
    add(t3);
add(t4);
add(t5);    
 add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
    add(l6);

 add(pic);

setVisible(true);

try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Allah");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery("SELECT * FROM student");
JOptionPane.showMessageDialog(null," connection created","Msg",2);
   }

 catch(Exception e)
  {
JOptionPane.showMessageDialog(null,e,"Msg",2);
   }

}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getSource()==bt1)
{
rs.next();
if(rs.isAfterLast())
rs.first();
t1.setText(rs.getString(1));
t2.setText(rs.getString(2));
t3.setText(rs.getString(3));
t4.setText(rs.getString(4));
t5.setText(rs.getString(5)); }

     if(ae.getSource()==bt2)
     { 
       rs.previous();
       if(rs.isBeforeFirst())
       rs.last();
           t1.setText(rs.getString(1));
       t2.setText(rs.getString(2));
       t3.setText(rs.getString(3));
       t4.setText(rs.getString(4));
           t5.setText(rs.getString(5)); 
      }
        }

catch(Exception e)
    {
      JOptionPane.showMessageDialog(null,e,"Msg",2);
     }
  }

}
class data
{
public static void main(String str[])
{
new kaleem();
}
}

Here is also different java and asp.net programs like:

  1. How to Create combo box in java|Complete Coding
  2. Java program to calculate Age from Date of birth
  3. How to create a Recruitment or job announcement page in asp.net | Complete front end designing and backend coding
  4. How to Add multiple textbox values and showing their sum
  5. Employee Registration form | Creation of Registration form in visual studio using c# and asp.net
  6. How add new webpage in a website using C#, asp.net in visual studio.
  7. How to create login page using asp.net and C#

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *