JBBC ,MYSQL ND JAVA

JBBC ,MYSQL ND JAVA

import java.sql.*;
import javax.swing.JOptionPane;

public class NewJFrame extends javax.swing.JFrame {

Connection con=null;
 Statement st=null;
 ResultSet rs=null;

public NewJFrame() {
    initComponents();
}

private void initComponents() {


private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
    {
        try
            Class.forName("java.sql.Driver");
        con=DriverManager.getConnection("jdbc:mysql://localhost/ACCOUNT","root","ADMIN");
        st=con.createStatement();
        String query="SELECT * FROM BANK";
        rs=st.executeQuery(query);
        if(rs.next())

    {
            String n=rs.getString("name");
            String b=rs.getString("address");
             String s=rs.getString("phone");
             String t=rs.getString("branch");

    }
        else
        {
            JOptionPane.showMessageDialog(null,"no record");
        }

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

CAN ANYONE HELP ME IN FINDING THE ERRORS IN DIS CODE AND WATS REALLY A PROBLEM WITH THIS?

View Answers

January 18, 2011 at 5:42 PM

Hi Friend,

We have modified your code, there were many errors.Try this:

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

public class NewJFrame extends JFrame {
Connection con=null; 
Statement st=null;
ResultSet rs=null;

public NewJFrame() {
    initComponents();
}
private void initComponents() {
setLayout(null);
JButton b=new JButton("Retrieve");
b.setBounds(10,10,100,20);
add(b);
setSize(300,100);
setVisible(true);

b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
        try{
        Class.forName("com.mysql.jdbc.Driver");
        con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
        st=con.createStatement();
        String query="SELECT * FROM employee";
        rs=st.executeQuery(query);
        int count=0;
        while(rs.next()){
            String n=rs.getString("name");
            String b=rs.getString("address");
            String s=rs.getString("contactNo");
            String t=rs.getString("email");
            System.out.println(n+" "+b+" "+s+" "+t);
            count++;
            }
            if(count<0){
            JOptionPane.showMessageDialog(null,"no record");
            }
        }
        catch(Exception e) {
        JOptionPane.showMessageDialog(null,"error"); 
        }
    }
});
}
public static void main(String[]args){
    new NewJFrame();
}
}

For more information, visit the following link:

JDBC Tutorial

Thanks


January 19, 2011 at 6:33 PM

thanks thankz... thnks a lot frnd.. actually dt code s printed in ma txt buk and wn i tryd to run on ma system oh god... wt to say full error... can u plz help me to design a gui programme with the help of d same.. i mean we'v to input data in a designed gui frame and d data which v input should get saved in a mysql table... plz if u've any such programmes kindly help me..

Ads









Related Tutorials/Questions & Answers:
JBBC ,MYSQL ND JAVA
JBBC ,MYSQL ND JAVA  import java.sql.*; import...:mysql://localhost/ACCOUNT","root","ADMIN"); st=con.createStatement...("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test
write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string
write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string    write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string ex:If a user enters
Advertisements
ModuleNotFoundError: No module named 'nd'
ModuleNotFoundError: No module named 'nd'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'nd' How to remove the ModuleNotFoundError: No module named 'nd' error
ModuleNotFoundError: No module named 'nd'
ModuleNotFoundError: No module named 'nd'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'nd' How to remove the ModuleNotFoundError: No module named 'nd' error
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
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
Version of mysql>mysql-connector-java dependency
List of Version of mysql>mysql-connector-java dependency
mysql-java
mysql-java   i try to execute this code stmt1.executeUpdate("insert... the manual that corresponds to your MySQL server version for the right syntax to use...) at Mydb.main(Mydb.java:111) Java Result: 1 please help me to find the error  
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
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
Java connectivity with MySQL
Java connectivity with MySQL  Java connectivity with MySQL
MySql,java
MySql,java  In MySQL table i am adding the fields of name,photo,video,age,category.in the category i have some subjects.if one person login into my-site the he upload the one video under one subject.then i want the following
ModuleNotFoundError: No module named 'augment-nd'
ModuleNotFoundError: No module named 'augment-nd'  Hi, My Python... 'augment-nd' How to remove the ModuleNotFoundError: No module named 'augment-nd' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'nd-primer'
ModuleNotFoundError: No module named 'nd-primer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'nd-primer' How to remove the ModuleNotFoundError: No module named 'nd
ModuleNotFoundError: No module named 'nd-primer'
ModuleNotFoundError: No module named 'nd-primer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'nd-primer' How to remove the ModuleNotFoundError: No module named 'nd
ModuleNotFoundError: No module named 'nd-project'
ModuleNotFoundError: No module named 'nd-project'  Hi, My Python... 'nd-project' How to remove the ModuleNotFoundError: No module named 'nd... have to install padas library. You can install nd-project python
ModuleNotFoundError: No module named 'nd-project'
ModuleNotFoundError: No module named 'nd-project'  Hi, My Python... 'nd-project' How to remove the ModuleNotFoundError: No module named 'nd... have to install padas library. You can install nd-project python
ModuleNotFoundError: No module named 'nd-primer'
ModuleNotFoundError: No module named 'nd-primer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'nd-primer' How to remove the ModuleNotFoundError: No module named 'nd
ModuleNotFoundError: No module named 'nd-project'
ModuleNotFoundError: No module named 'nd-project'  Hi, My Python... 'nd-project' How to remove the ModuleNotFoundError: No module named 'nd... have to install padas library. You can install nd-project python
ModuleNotFoundError: No module named 'dist-nd-lesson'
ModuleNotFoundError: No module named 'dist-nd-lesson'  Hi, My... named 'dist-nd-lesson' How to remove the ModuleNotFoundError: No module named 'dist-nd-lesson' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'dsnd-distributions-QianLiu-nd'
ModuleNotFoundError: No module named 'dsnd-distributions-QianLiu-nd'  ...: No module named 'dsnd-distributions-QianLiu-nd' How to remove the ModuleNotFoundError: No module named 'dsnd-distributions-QianLiu-nd' error
ModuleNotFoundError: No module named 'dsnd-distributions-QianLiu-nd'
ModuleNotFoundError: No module named 'dsnd-distributions-QianLiu-nd'  ...: No module named 'dsnd-distributions-QianLiu-nd' How to remove the ModuleNotFoundError: No module named 'dsnd-distributions-QianLiu-nd' error
ModuleNotFoundError: No module named 'me-nd-distributions'
ModuleNotFoundError: No module named 'me-nd-distributions'  Hi, My... named 'me-nd-distributions' How to remove the ModuleNotFoundError: No module named 'me-nd-distributions' error? Thanks   Hi
ModuleNotFoundError: No module named 'nd_service_registry'
ModuleNotFoundError: No module named 'nd_service_registry'  Hi, My... named 'nd_service_registry' How to remove the ModuleNotFoundError: No module named 'nd_service_registry' error? Thanks   Hi
ModuleNotFoundError: No module named 'nd_service_registry'
ModuleNotFoundError: No module named 'nd_service_registry'  Hi, My... named 'nd_service_registry' How to remove the ModuleNotFoundError: No module named 'nd_service_registry' error? Thanks   Hi
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
mysql
you need to download the mysql-connector jar file for connecting java program from mysql database.......   Hi friend, MySQL is open source database... is the link for the page from where you can understand how to Download and Install MySQL

Ads