• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JTable type yes/no

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am having a problem in displaying the table when i have a yes/no data type. how can i solve this problem?
cause if i add it inside the acess... and run it, the table appear but it's blank. why can't it accept other data type besides text?
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can. If you add Boolean values, you end up with a checkbox. It will take any Object.
 
sae0203
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but the problem is the table won't shown if i add a boolean type data in the access... wat are the codes that i must add to fix this problem
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Boolean not boolean
 
sae0203
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
below is the code i have for my JTable. but when i add the data type yes/no format true/false.how do i change the code in the column header so that it can accept the data type.....
URGENT HELP NEEDED thanks

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TableDisplay extends JFrame
{
private Connection connection;
private JTable table;

public TableDisplay()
{
String url = "jdbc dbc:Mega Book";
String username = "anonymous";
String password = "guest";

//Load the driver to allow connection to the database
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connection=DriverManager.getConnection
(url, username,password);
}

catch(ClassNotFoundException cnfex)
{
System.err.println("Failed to load JDBC/ODBC driver.");
cnfex.printStackTrace();
System.exit(1); //terminate program
}
catch(SQLException sqlex)
{
System.err.println("Unable to connect");
sqlex.printStackTrace();
}
getTable();

setSize(450, 150);
show();
}

private void getTable()
{
Statement statement;
ResultSet resultSet;

try
{
String query="SELECT * FROM Inventory"; //String query="SELECT * FROM Authors";

statement = connection.createStatement();
resultSet = statement.executeQuery(query);
displayResultSet(resultSet);
statement.close();
}
catch (SQLException sqlex)
{
sqlex.printStackTrace();
}
}

private void displayResultSet(ResultSet rs) throws SQLException
{
//position to first record
boolean moreRecords = rs.next();

//if there are no records, display a message
if(!moreRecords)
{
JOptionPane.showMessageDialog(this,"ResultSet contained no records");
setTitle("No records to display");
return;
}

setTitle("Inventory");

Vector columnHeads = new Vector();
Vector rows = new Vector();

try
{
//get column heads
ResultSetMetaData rsmd = rs.getMetaData();
for(int i=1; i<=rsmd.getColumnCount();++i)
columnHeads.addElement(rsmd.getColumnName(i));

//get row data
do
{
rows.addElement(getNextRow(rs,rsmd));
}while(rs.next());

//display table with ResultSet contents
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:currentRow.addElement(rs.getString(i));
break;
case Types.INTEGER:currentRow.addElement(new Long(rs.getLong(i)));
break;
default:System.out.println("ID 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 TableDisplay app=new TableDisplay();

app.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
app.shutDown();
System.exit(0);
}

}
);
}
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic