DATA BASE

DATA BASE

Create a program to establish a connection to the PCTBC database using the JDBC driver to retrieve the entire Lectures table and displays the data using a J Table.

View Answers

September 17, 2012 at 11:16 AM

Here is a code that connects to MySql database and retrieve the records from database to jtable.

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("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
String sql = "Select name,address 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 Tutorials/Questions & Answers:
data base
data base  how to connect coding in data base ?   The given code connects JSP page to database. You need to import the mysql connection jar file to jdk as well as to the lib of tomcat. Moreover you need to set classpath
DATA BASE
DATA BASE  Create a program to establish a connection to the PCTBC... the data using a J Table.   Here is a code that connects to MySql... main(String[] args) { Vector columnNames = new Vector(); Vector data = new Vector
Advertisements
Data base Connectivity
Data base Connectivity  How to configure JDBC connection for Oracle data base.In configuring it is asking select Data server name and TNS.I typed Oracle for Data Server Name and IN TNS what to type? I pulled the list for TNS
Data base related question
Data base related question  sir my table has only one element(that is pno),i am using ms-access as backend. i put only one element i want to retrieve that element .how can i retrieve that element,using jdbc technology. please
JSP data base validation
JSP data base validation  please explain how to validate form input string with database n also how its notify that entered data exists already... bol = ps.execute(); out.println("Data Added Successfully
Data base - JDBC
Data base  I want to do this Inserting a record with Object type column using PreparedStatement but wht should b the column datatype this is te..."); con.close(); }//main }//class For this should i create a user defined data type
please send me the banking data base in swings
please send me the banking data base in swings  sir, please send me how to create the banking data base program in swings
ModuleNotFoundError: No module named 'odoo10-addon-l10n-br-data-base'
ModuleNotFoundError: No module named 'odoo10-addon-l10n-br-data-base' ...: No module named 'odoo10-addon-l10n-br-data-base' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-l10n-br-data-base' error
ModuleNotFoundError: No module named 'odoo8-addon-l10n-br-data-base'
ModuleNotFoundError: No module named 'odoo8-addon-l10n-br-data-base'  ...: No module named 'odoo8-addon-l10n-br-data-base' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-l10n-br-data-base' error
Retrive the data from the table in data base using jdbc
Retrive the data from the table in data base using jdbc  Retrive the data from the table in data base using jdbc   JDBC Tutorials
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
for store data in data base - JSP-Servlet
for store data in data base  i want to a job site, in this site user can registered by a form.. in this form there are his information... i use..... and on 3rd form i use submit button... data of form 1 and 2 can also be store
when refreshing the page the data is stored in data base again
when refreshing the page the data is stored in data base again  Hi, In my application, I am adding form data in database on click of submit button.But the problem is, when user refreshes the page, the data added one more time
Retrieving data from data base using jsp combo box
Retrieving data from data base using jsp combo box  Hi guys please help me , i have on GUI page int that Server type(like apache,jboss,weblogic) one combo box is there and another filed is version of the server(like 1.0,2.0) like
retrive data from data base and print it in every page until logout
retrive data from data base and print it in every page until logout  suppose that a user login your website through user name & password. now after completion of login he goto home page.inside home page i want to print
data base question - Java Interview Questions
data base question  first we create a table with out create primary kay,after that i want to create same record with primary key,but no duplicate record,no deletion and after creation.  Hi, Query to create
What is the average base salary of a Data Scientist reported by The New York Times?
What is the average base salary of a Data Scientist reported by The New York Times?  Hi, I am beginner in Data Science and machine learning field. I... base salary of a Data Scientist reported by The New York Times?". Also tell
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am...;AdminProvideLeave>(); try { > Query q = session.createQuery("from >...;AdminLeavePojo> adlp = null; > try { Query q = > session.createQuery
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am...;AdminProvideLeave>(); try { > Query q = session.createQuery("from >...;AdminLeavePojo> adlp = null; > try { Query q = > session.createQuery
data fecth from data base in( sql 2000) htmlform and jsp
data fecth from data base in( sql 2000) htmlform and jsp  hi iam using jsp and html form data fecth from database display the textbox help me i want whenever select from dropdown list select the projectname to display
insert excel value in to oracle data base
insert excel value in to oracle data base  Hi All I am using...); System.out.println("Data is inserted..., You can read the data from the excel file using JDBC. For this you need
java code for threading example for connecting data base
java code for threading example for connecting data base  Write a program that has two threads First thread queries the database and fetches all the employee records from the emp table. Stores the employee objects
how to insert the bulk data into the data base from the table of jsp page to another jsp page
how to insert the bulk data into the data base from the table of jsp page to another jsp page  pls help i'm doing the project called centralized... to insert the marks details into the data base i have retrive the rollno and name
getting int values from form and insert it in data base in jsp
getting int values from form and insert it in data base in jsp  how... = Integer.parseInt(s); Then you can write JDBC code to insert data...=st.executeUpdate("insert into data(name,age, address) values('"+name+"',"+age
How to create a Student data base using Linked List in java
How to create a Student data base using Linked List in java  I want a program by using linked list in java. The data stored must... no to display: "); String rec=input.next(); for(StudentData data:list
J2ME Record Data Base
J2ME Record Data Base       This Application is used to explain how to store data in the database... the RecordStore class. The RecordStore class is used to get the data through
How to create a data base connectivity using sqlserver or Mydql through J2ME - JDBC
How to create a data base connectivity using sqlserver or Mydql through J2ME   hi , iam new to J2ME,i want to know, How to create a data base... with the sqlserver2000 database. so i want to update the data into database as well
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.  <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8
data
data  Handling data
data
data  data Handling AOP
data
data  Handling data in AOP
data
data handling examples in AOP Model  data handling examples in AOP Model
extract data from HTML
extract data from HTML  how to write the coding for to extract data from html tags like(h3,p) and then extracted data should be stored in data base? can anybody tell me how to write the coding
JAVA AWT BASE PROJECT
JAVA AWT BASE PROJECT  suggest meaningful java AWT-base project
ModuleNotFoundError: No module named 'base'
ModuleNotFoundError: No module named 'base'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'base' How to remove the ModuleNotFoundError: No module named 'base' error
about the base class of file
about the base class of file  what is the basic class of file
base calculator.. - Java Beginners
base calculator..  Help, i need some help about a base calculator.. i don't know how to start
Version of com.fitbur>base dependency
List of Version of com.fitbur>base dependency
Version of com.routing4you>base dependency
List of Version of com.routing4you>base dependency
Version of com.thesett>base dependency
List of Version of com.thesett>base dependency
Version of cn.knero>base dependency
List of Version of cn.knero>base dependency
Version of com.ruijc>base dependency
List of Version of com.ruijc>base dependency
Lang and Util Base Libraries
Lang and Util Base Libraries The Base libraries provides us the fundamental features and functionality of the Java platform. Lang and Util Packages Lang... preferences of system and user and also data of configuration. Click here to go
HTML - base tag example.
HTML - base tag example. Description : The base tag is a HTML tag. It specifies a base(default) URL for all link in the page. Code : <html> <head> <base href="http://roseindia.net"> <
Other Base Packages
Other Base Packages I/O For handling i/o of an application in java , java.io & java.nio package is available. Object Serialization... for processing of XML data and documents. Java Native Interface (JNI) JNI stands
importing data and edit that data
importing data and edit that data   hello sir i have data in excel sheet which contain 2 rows and i want to import that data to ms access and edit that data like adding new columns and new rows and creating new tables
What is the base class of all classes?
What is the base class of all classes?  Hi, What is the base class of all classes? thanks   Hi, The base class is nothing but the Abstract class of Java programming. We uses the syntax for base class of all
big data data science
big data data science  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: big data data... the topic "big data data science". Also tell me which is the good
data science and data mining
data science and data mining  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: data science and data mining Try to provide me good examples or tutorials links so that I
data mining data science
data mining data science  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: data mining data science Try to provide me good examples or tutorials links so that I can

Ads