wood burning stoves 2.0*
The moose likes Java in General and the fly likes urgent: retrieval of data from database to JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "urgent: retrieval of data from database to JList" Watch "urgent: retrieval of data from database to JList" New topic
Author

urgent: retrieval of data from database to JList

sandeep sahni
Greenhorn

Joined: Feb 22, 2005
Posts: 1
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.sql.*;


class connection
{
Connection conn;
String url;
Statement stmt;


{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="jdbc dbc:java";
conn=DriverManager.getConnection(url);
System.out.println("Successfully Connected");
conn.close();
}
catch(SQLException sqlExcep)
{
System.out.println("Error: "+ sqlExcep.getMessage());
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Error: "+ cnfe.getMessage());
}
}
public void showmess()
{
System.out.println("Successfully Connected");
}
}
public class fpage4 extends JFrame
{
public fpage4()
{
JButton btn1,btn2,btn3,btn4;
ImageIcon i1,i2,i3,i4;
JList list;
DefaultListModel listModel;

Container contentPane=getContentPane();
JPanel button=new JPanel(new FlowLayout());
i1 =new ImageIcon("chat/images/smile.gif");

btn1=new JButton("Friend",i1);
btn1.setBackground(Color.white);
btn1.setToolTipText("To Add a Friend");
button.add(btn1);
//btn1.addActionListener(this);

i2=new ImageIcon("chat/images/cool.gif");

btn2=new JButton("All Users",i2);
btn2.setBackground(Color.white);
btn2.setToolTipText("To Display all Users");
button.add(btn2);
//btn2.addActionListener(this);


i3=new ImageIcon("chat/images/blush.gif");

btn3=new JButton("Online",i3);
btn3.setBackground(Color.white);
btn3.setToolTipText("To Display Online Users");
button.add(btn3);
//btn3.addActionListener(this);


i4=new ImageIcon("chat/images/frown.gif");

btn4=new JButton("Offline",i4);
btn4.setBackground(Color.white);
btn4.setToolTipText("To Display Offline Users");
button.add(btn4);
//btn4.addActionListener(this);

JPanel j1=new JPanel(new GridLayout(1,1,2,2));
button.setBackground(Color.blue);


String[] items = {"a","b","c","d","e"};
list = new JList(items);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list.setLayoutOrientation(JList.VERTICAL_WRAP);
list.setVisibleRowCount(5);
list.setFixedCellWidth(55);
list.setSelectedIndex(0);

//DefaultListModel model=new DefaultListModel();
//list=new JList(model);

JScrollPane ListscrollPane =
new JScrollPane(list,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
j1.add(ListscrollPane);


JPanel main=new JPanel(new BorderLayout());
contentPane.setLayout(new FlowLayout());

main.add("Center",j1);
main.add("North",button);
contentPane.setBackground(Color.pink);

contentPane.add(main);
}

public static void main(String args[]) throws Exception
{
fpage4 frmpage=new fpage4();

connection obj=new connection();



Connection conn;

Statement stmt;

String query="select * from tbl_frend";

try
{
ResultSet rs;
conn=DriverManager.getConnection("jdbc dbc:java");
stmt=conn.createStatement();

stmt.executeQuery("Select * from tbl_frend");

System.out.println("\n");


rs=stmt.executeQuery(query);

while(rs.next())
{

String friend_name=rs.getString("friend_name");

System.out.println(friend_name +"\n");



}

stmt.close();

conn.close();
}
catch(SQLException sqle)
{
System.out.println("SQLException: "+sqle.getMessage());
}


frmpage.setSize(500,300);
frmpage.setVisible(true);

WindowListener listener=new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
};
frmpage.addWindowListener(listener);
}
}

IF POSSIBLE PLEASE MAKE THE CHANGES TO THIS EXISTING CODE IT DOES NOT RETRIEVE THE LIST OF FRIENDS FRO THE DATABASE TABLE tbl_frend...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: urgent: retrieval of data from database to JList
 
Similar Threads
What happens to events when an actionlistener is hogging the event dispatch thread
Pressing ENTER when Button is selected doesnt fire buttonActionPerformed...
Button and Keyboard linking
How to navigate between multiple GUI classes
Clearing a JList