Home Answers Viewqa Swing-AWT swing with jdbc

 
 


prashant
swing with jdbc
2 Answer(s)      4 years and a month ago
Posted in : Swing AWT

View Answers

May 16, 2009 at 4:25 PM


Hi Friend,

To insert the table values, try the following code:

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

public class InsertJTableDatabase{
JTable table;
JButton button;
public static void main(String[] args) {
new InsertJTableDatabase();
}

public InsertJTableDatabase(){
JFrame frame = new JFrame("Getting Cell Values in JTable");
JPanel panel = new JPanel();
String data[][] = {{"Angelina","Mumbai"}};
String col[] = {"Name","Address"};
DefaultTableModel model = new DefaultTableModel(data, col);
table = new JTable(model);
JScrollPane pane = new JScrollPane(table);
button=new JButton("Submit");
Object obj1 = GetData(table, 0,0);
Object obj2= GetData(table, 0,1);

final String value1=obj1.toString();
final String value2=obj2.toString();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
PreparedStatement pstm;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connect =DriverManager.getConnection("jdbc:odbc:access");
pstm=connect.prepareStatement("insert into data values(?,?)");
pstm.setString(1,value1);
pstm.setString(2,value2);
pstm.executeUpdate();
}
catch(Exception e){}
}
});
panel.add(pane);
panel.add(button);
frame.add(panel);
frame.setSize(500,250);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public Object GetData(JTable table, int row_index, int col_index){
return table.getModel().getValueAt(row_index, col_index);
}
}

May 16, 2009 at 4:26 PM


continue.......................

Now to retrieve the database value in JTable, try the following code:

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

public class JTableDatabase extends JFrame{
public JTableDatabase() {
Vector columnNames = new Vector();
Vector data = new Vector();

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connect =DriverManager.getConnection("jdbc:odbc:access");

String sql = "Select * from data";
Statement stmt = connect.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);

JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane );

JPanel buttonPanel = new JPanel();
getContentPane().add( buttonPanel, BorderLayout.SOUTH );
}
public static void main(String[] args)
{
JTableDatabase frame = new JTableDatabase();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}
}

Thanks









Related Pages:
swing with jdbc - Swing AWT
have some problems with swing using jdbc. 1. the values entered in table are not stored in DB. 2. is there is any solution that uses jtable with JDBC? kindly...swing with jdbc  Hi, i m developing the desktop application using
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those... in a table. Use JDBC
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those... in a table. Use JDBC
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
jdbc &swing - Java Beginners
jdbc &swing  I've used a progress bar in a database file upload window using swing.. But I can't set the uploading processing time with the progress bar.. please help me as early as possible.. How can I use progress bar against
java swing jdbc - Java Beginners
java swing jdbc  hello, i want to populate the data(ms access) to the jtable component and want to perform some operations on it like add,edit,delete. Again i want to store the updated data to the database. can you help me out
Swing Program
Swing Program  Write a java swing program to search the details of the students. Searching is performed on student's first name. The details of all... will be displayed in a table, and also delete a selected record from a table. Use JDBC
jdbc - JDBC
: http://www.roseindia.net/jdbc/save_image.shtml Retrieve Image using Java Swing: import java.sql.*; import java.awt.*; import javax.swing.... = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test", "root", "root
java swing - Swing AWT
("com.mysql.jdbc.Driver"); Connection connect =DriverManager.getConnection("jdbc:mysql
jdbc,odbc,MySQL,swing - Java Beginners
jdbc,odbc,MySQL,swing  write a code that displays a menu list of all available database drivers in a window,and allows the user to select any driver... to the selected database driver.It is very well known as jdbc front end of a database
regarding jdbc - JDBC
regarding jdbc  is there any way in jdbc to retieve data from a table and show it by using swing concept i mean to say data from the table can be shown in swing interface with tabular form
Swing Program
Swing Program  write a java swing program to get username and password. The name contains only characters while password is masked...("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st
Java swing
Java swing  when i enter the time into the textbox and activities into the textarea the datas saved into the database.the java swing code... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root
swing question
swing question  please provide me a program with oracle conectivity in which it consist of a log in page. and when i clicked login it takes data from... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
java swing
java swing  what is code for diplay on java swing internal frame form MYSQL DB pls send   Here is a code of creating form... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
Java swing in NetBeans - Swing AWT
Java swing in NetBeans   thanks a lot sir for everything you answered.... i will specify a swing code for JTable using NETBEANS so would you tell me...=DriverManager.getConnection("jdbc:odbc:Stu","admin","admin"); try
Java swing
"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root
jdbc front end - JDBC
jdbc front end  a code written using JDBC,ODBC,SQL and swing only that allows the user to select the required driver related to a specific database..."); Connection connect =DriverManager.getConnection("jdbc:odbc:access","",""); Statement st
jdbc odbc
jdbc odbc  i want to fetch the data from the ms access and print on ms word for printing purpose?? the whole program is in swing to ms acess connectivity.. the whole set up is perform only printing part is remaining? so help me
jdbc odbc
jdbc odbc  i want to fetch the data from the ms access and print on ms word for printing purpose?? the whole program is in swing to ms acess connectivity.. the whole set up is perform only printing part is remaining? so help me
Sitemap Java Swing Tutorial
Map | Business Software Services India JPA Tutorial Section JDBC vs...-to-One Relationship | JPA-QL Queries Java Swing Tutorial Section Java Swing Introduction | Java 2D API | Data Transfer in Java Swing
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
java - Swing AWT
java  how can i add items to combobox at runtime from jdbc  .../java/example/java/swing/AddRemoveItemFromCombo.shtml Thanks  Hi Friend..."); Connection conn = DriverManager.getConnection("jdbc:odbc:access
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root
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... = DriverManager.getConnection("jdbc:odbc:roseindia"); String sql = "Select * from
swing
swing  Write a java swing program to delete a selected record from a table
swing
swing  How to make swing component auto-resizable when JFrame resize
JTree - JDBC
JTree  how to retrieve data from database into JTrees?   JTree - Retrieve data from database http://www.roseindia.net/java/example/java/swing/retrieving-jtree-structure-from.shtml Find out your answer from above
jdbc odbc
= DriverManager.getConnection("jdbc:odbc:swing"); String sql = "INSERT...jdbc odbc  Sir, i want to get the selected value from JCombobox to ms...://www.roseindia.net/java/example/java/swing/store-jcombobox-selecteditem-value
Swing Application help
Swing Application help  Hi am developing an application. I have set...;Here is a swing application that will insert the form data into database...("jdbc:mysql://localhost:3306/test", "root", "root" ); Statement st
JTree - JDBC
://www.roseindia.net/java/example/java/swing/retrieving-jtree-structure-from.shtml
java swing - Java Beginners
(){ JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane().setLayout(null... = DriverManager.getConnection("jdbc:odbc:access"); PreparedStatement st=con.prepareStatement("insert
jdbc & sql related project - JDBC
jdbc & sql related project  code using jdbc,odbc,swing,MySql classes to create front-end of any jdbc that allows the user to select any database... = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "root
java - JDBC
java  how to access excel file through jdbc show record in table in swing.   Hi Friend, Follow these steps: 1. Open Data Sources...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn=DriverManager.getConnection("jdbc:odbc:excel
Jdbc RowSet
"); Connection con = DriverManager.getConnection("jdbc:odbc:swing...Jdbc RowSet  import java.sql.*; import javax.sql.*; import...=DriverManager.getConnection("jdbc:odbc:oradsn","scott","tiger"); Statement stmt
Date - Swing AWT
,month,year into MS-Access using JDBC. 3.it should be in Format DD-MM-YY... = DriverManager.getConnection("jdbc:odbc:access"); PreparedStatement pstmt
Swing Jobs at Rose India
Swing Jobs at Rose India       This Swing Job is for fresher and experienced swing programmers. Due to our expansion we are in the process of hiring
java - Swing AWT
= null; String url = "jdbc:mysql://localhost:3306/"; String db = "test...(); String value6=text5.getText(); Connection con = null; String url = "jdbc
Java question - Swing AWT
= DriverManager.getConnection("jdbc:mysql://localhost:3306/register", "root", "root
jdbc oracle connectivity problem
jdbc oracle connectivity problem  Hi All, I am trying to connect my swing application to oracle DB . but class.forname is giving error. Please suggest me if there is some different way to connect swing application to oracle
Java Program - Swing AWT
= DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
java swing - Java Beginners
= DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
JDBC Tutorial, JDBC API Tutorials
to use JDBC API effectively to develop database driven applications in Java. You can use JDBC in your console, AWT, Swing and Web applications. JDBC API provides...Java Database Connectivity(JDBC) Tutorial This tutorial on JDBC explains you
how to connect two swing frames
how to connect two swing frames  how to connect two swing frames   Hi Friend, Try this: 1)LoginDemo.java: import java.sql.*; import...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc
Need source code - Swing AWT
Need source code  Hai, In java swing, How can upload and retrieve... actionPerformed(ActionEvent e){ try{ Connection con = null; String url = "jdbc:mysql... = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test", "root