Home Answers Viewqa JDBC JTABLE IS NOT RETIVING DATE FROM MS ACCESS

 
 


Ocean Pearl
JTABLE IS NOT RETIVING DATE FROM MS ACCESS
1 Answer(s)      a year and 3 months ago
Posted in : JDBC

PLEZ help me to retrive date from access to jtable.......

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

public class StudentIssueView extends  JFrame {
    private Connection connection;
    private JTable  table;
    private Object currentRow;

    public StudentIssueView  ()
    {

       try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            connection=DriverManager.getConnection("jdbc:odbc:college" );
        }
        catch(ClassNotFoundException cnfex) {
            System.err.println("Failed to load Jdbc/Odbc driver.");
            cnfex.printStackTrace();
            System.exit(1);
          }
        catch(SQLException sqlex) {
            System.err.println("Unable to connect");
            sqlex.printStackTrace();
        }
        getTable();
        setSize(1000,150);
        setVisible(true);
        setResizable(false);
    }
    private void getTable()
    {
        Statement statement;
        ResultSet resultSet;

        try
 {
            String  query="Select * from Student";
            statement=connection.createStatement();
            resultSet=statement.executeQuery(query);
            displayResultSet(resultSet);
            statement.close();
            }
        catch(SQLException sqlex) {
            sqlex.printStackTrace();
        }
    }
    private void displayResultSet(ResultSet rs)throws SQLException
    {
        boolean moreRecords=rs.next();

        if(!moreRecords) {
            JOptionPane.showMessageDialog(this, "ResultSet contained no records");
            setTitle("No records to display");
            return;
        }
        setTitle("Student Book Issue Details");
        Vector columnHeads=new Vector();
        Vector rows=new Vector();

        try {
            ResultSetMetaData rsmd=rs.getMetaData();

            for(int i=1; i<=rsmd.getColumnCount(); i++)
                columnHeads.addElement(rsmd.getColumnName(i));

            do {
                rows.addElement(getNextRow(rs, rsmd));

            } while(rs.next());
            table =new JTable(rows, columnHeads);
            JScrollPane scroller=new JScrollPane(table);
            getContentPane().add(scroller, BorderLayout.CENTER);
            validate();
        }
        catch(SQLException sqlex) {
            sqlex.printStackTrace();
        }
    }
    private Vector getNextRow(ResultSet rs, ResultSetMetaData rsmd)throws SQLException
    {
        Vector currentRow=new Vector();

        for(int i=1; i <= rsmd.getColumnCount(); ++i)
            switch(rsmd.getColumnType(i)) {
                case Types.VARCHAR:

HAR:
                    currentRow.addElement(rs.getString(i));
                   break;
                case Types.INTEGER:
                    currentRow.addElement( new Long(rs.getLong(i)));
                    break;
                case Types.DATE:
                    currentRow.addElement( new Long(rs.getLong(i)));
                    break;
                case Types.TIME:
                    currentRow.addElement( new Long(rs.getLong(i)));
                    break;  
                 default:
                   System.out.println("Type was:" + rsmd.getColumnTypeName(i));
                     }
               return currentRow;
    }
    public void shutDown()
    {
        try {
            connection.close();
        }
        catch(SQLException sqlex)
        {
            System.err.println("Unable to disconnect");
            sqlex.printStackTrace();
        }
    }
    public static void main(String args[])
    {
        final StudentIssueView app=new StudentIssueView();
        app.addWindowListener(
                new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e)

            {
                app.shutDown();
                System.exit(0);

            }
        });
    }

}
View Answers

February 28, 2012 at 11:00 AM


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

public class JTableDatabase {
public static void main(String[] args) {
Vector columnNames = new Vector();
Vector data = new Vector();
JPanel p=new JPanel();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
String sql = "Select * from data";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( sql );
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 );
}
rs.close();
stmt.close();
}
catch(Exception e){
System.out.println(e);
}
JTable table = new JTable(data, columnNames);
TableColumn col;
for (int i = 0; i < table.getColumnCount(); i++) {
col = table.getColumnModel().getColumn(i);
col.setMaxWidth(250);
}
JScrollPane scrollPane = new JScrollPane( table );
p.add( scrollPane );
JFrame f=new JFrame();
f.add(p);
f.setSize(600,400);
f.setVisible(true);
}
}









Related Pages:
How to use JTable with MS-Access
.   Here is an example that retrieves the data from MS Access database...How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display
How to use JTable with MS-Access
.   Here is an example that retrieves the data from MS Access database...How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display
ms access
and password" from my ms access............and detail in register(table in my ms... "username and password" from my ms access............and detail in register(table in my... has to login . i already created ms access page and inserted values throught
ms access
and password" from my ms access............and detail in register(table in my ms... "username and password" from my ms access............and detail in register(table in my... has to login . i already created ms access page and inserted values throught
ms access
and password" from my ms access............and detail in register(table in my ms... "username and password" from my ms access............and detail in register(table in my... has to login . i already created ms access page and inserted values throught
ms access
and password" from my ms access............and detail in register(table in my ms... "username and password" from my ms access............and detail in register(table in my... has to login . i already created ms access page and inserted values throught
How To Display MS Access Table into Swing JTable - Java Beginners
How To Display MS Access Table into Swing JTable  How to Display Records From MS Access Database To JTable. Plz Help Me  Hi Friend... = DriverManager.getConnection("jdbc:odbc:access"); String sql = "Select * from
ms access
ms access  how to delete the autonumber from ms access using java delete code
Ms Access
Ms Access   How to get query for Primary key from MsAccess?   SELECT column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_name = 'data';   SELECT column_name FROM INFORMATION_SCHEMA.KEY_COLUMN
How To Display both image and data into Swing JTable which is retrieved from ms access database
How To Display both image and data into Swing JTable which is retrieved from ms access database  So far this is my code how can i display both image and data from database.. while (rs.next()) { Vector row = new Vector(columns
Jdbc MS-Access question
Jdbc MS-Access question  How to delete records from the three table in MS-Access? They are in relationship with each other regarding to data field
Jdbc MS-Access question
Jdbc MS-Access question  How to delete records from the three table in MS-Access? They are in relationship with each other regarding to data field
Migrating from mysql to MS Access
Migrating from mysql to MS Access  Hi I am hoping for some help I need to write a conversion program (SQL statements) to import existing data in a MYSQL database to a MS Access database. any suggestions would be appreciated
MS Access` - JDBC
MS Access`  Hello Sir, Thank you very much for your valuable... to insert image into MS Access Database. Now the task is how to retrieve the image from database. And i am developing a JFrame to retrieve tha fields from database
MS Access - JSP-Servlet
stepts 1.to configure the ms access database to your system control panel... in Connectivity in MS Access : import java.sql.*; public class...MS Access  hello sir, i want to use MS.Access as my database..so my
MS Access - JDBC
information about MS access database...but still i am having doubt in that topic. My problem is : Is there any jar to connect MS Access and java ... because... to be remember 1.to configure the ms access database to your system control
jtable
jtable  i have build an application and i retrieve data from... { private Vector<Vector<String>> data; //used for data from database... ="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=Employee.MDB
how to insert values from jsp into ms access
how to insert values from jsp into ms access   how to insert values using jsp into ms access database
MS Access - WebSevices
MS Access  hello sir, i am trying to write a code which should take images from a particular folder and data from MSAccess..please help me..thank..." which have access database and for images we have created a field in the table
java &ms access - JDBC
java &ms access  Seasons Greetings, Am, creating an application for a food festival using Java swing as front end and MS access as Backend... ve managed to populate the JComboBox using MS Access. The problem is only 8 per
accessing ms access through jsp
accessing ms access through jsp  i have 3 tables in my database employee,project,task if i put employee id the search field .i should get details from other table what all queries should i use in servlet file and i am using
how to access the MS ACCESS database with java
how to access the MS ACCESS database with java   how to access the MS ACCESS database with java how can we insert,delete,update,search records of ms access with java   Java MS Access database connectivity Follow
jdbc warning regarding to ms access
jdbc warning regarding to ms access  shows warning msg while compiling using ms access : warning: sun.jdbc.odbc.JdbcOdbcDriver is Sun proprietary API...=con.createStatement(); ResultSet rs= stmt.executeQuery("select * from tn"); while(rs.next
MS-ACCESS Query Problem - SQL
MS-ACCESS Query Problem  hi sir i have table which is initially... "Select * from Student where Course="BCA" and Class="I"; it may contain many... = DriverManager.getConnection("jdbc:odbc:access"); Statement st
problem in jsp using ms-access
problem in jsp using ms-access  after starting server(tomcat) wen v... and select the driver Microsoft Access Driver(*.mdb). 3)After selecting...(); ResultSet rs=st.executeQuery("select * from data"); while(rs.next()){ %>
MS access
MS access  how do i access my Ms-Access file placed in the same jar file where my application code/class file r present??? Want to access it via Code. Can anyone help me ? Please give reply urgent...   give me reply
to get picture from ms access database by jsp-servlet....
to get picture from ms access database by jsp-servlet....  I have inserted a picture in ms access data base,,,how we can retrieve that picture by using jsp
MS-Access
MS-Access  I am trying to upload a image to ms-acess using jsp,and my problem is that it shows some error int the browser that "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect ".I think i set
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database...-> data sources. 2)Click Add button and select the driver Microsoft Access... = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database Follow...-> data sources. 2)Click Add button and select the driver Microsoft Access... = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database...-> data sources. 2)Click Add button and select the driver Microsoft Access... = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb
java swing (jtable)
java swing (jtable)  hii..how to get values of a particular record in jtable from ms access database using java swing in netbeans..?? please help... from database and display it in jtable. import java.awt.*; import java.sql.
Jtable Question - Java Beginners
Jtable Question  Hello Sir, I have Created Database in MS access 2007 ,I want show the table data in to Swing JTable, How I can Show it, plz Help...:access"); String sql = "Select * from data"; Statement stmt = con.createStatement
How to Open Picture From M.S. Access Database using Java Servlet ?
How to Open Picture From M.S. Access Database using Java Servlet ?  Hi all my Friends I have below code which insert a picture into M.S. Access Database But i m still not able to open this picture through Java using M.S. Access
audio files in jdbc connectivity with ms-access - JDBC
audio files in jdbc connectivity with ms-access  i need to know how to retrieve audio files through jdbc connectivity with ms-access and how to play... static void main(String[] args) { try{ String url="jdbc:odbc:access"; File
JTable - Java Beginners
JTable  Hi, I have some problem with JTable. On show All button hit, I want to show all records on the panel in a table format from ms-sql server. my problem is with Jtable, sometimes it is visible and sometimes it is not. when
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
how to connect to MS access database in JSP?
how to connect to MS access database in JSP?  how to connect to MS access database in JSP? Any seetings/drivers need to be set or installed before... and select the driver Microsoft Access Driver(*.mdb). 3)After selecting the driver
applet connected to table in MS Access database
applet connected to table in MS Access database   i have connected my java code with the MS access database and this is my code, can anyone tell me...:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=faltu.mdb"; // String url = "jdbc
Select Employee and display data from access database in a jtable
Select Employee and display data from access database in a jtable  I... a employee's name from a comboBox and the jtable will be filled with all... name of the customer is stored in a access database. Below is how it should
updation problem during transaction to ms-access
updation problem during transaction to ms-access  Hey friends I am a beginner to java,and my problem is related to updation query in ms... is fired through a button .Now problem is at text fields are getting data from
updation problem during transaction to ms-access
updation problem during transaction to ms-access  Hey friends I am a beginner to java,and my problem is related to updation query in ms... is fired through a button .Now problem is at text fields are getting data from
updation problem during transaction to ms-access
updation problem during transaction to ms-access  Hey friends I am a beginner to java,and my problem is related to updation query in ms... is fired through a button .Now problem is at text fields are getting data from
updation problem during transaction to ms-access
updation problem during transaction to ms-access  Hey friends I am a beginner to java,and my problem is related to updation query in ms... is fired through a button .Now problem is at text fields are getting data from
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
How to Access MS Access in jar.
How to Access MS Access in jar.  how do i access my Ms-Access file... to access it via Code or is their any alter-native?? Do i need any Driver to do this ... i m able to access a Ms-access via JDBC but cant find the file wen
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
JTable in java - Java Beginners
JTable in java  Sir , I have created an application with a JTable showing the records of an MS Access database table. On the same frame I have... given one , JTable table; ....... .... table.print(); Here the error
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.