Results 1 to 1 of 1
Thread: Inheritence
- 12-04-2010, 10:11 AM #1
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 180
- Rep Power
- 0
Inheritence
I am facing a problem.I know that JAVA doesn't allow multiple inheritence.But I am need to do something like that.But how to????
Please check this and the question is written below...
Java Code:class databaseAccess extends javax.swing.JFrame { static JLabel jTextField1; static JLabel jTextField2; static JLabel jTextField3; static JLabel jTextField4; static JTextField jTextField5; static JTextField jTextField6; static JTextField jTextField7; static JPasswordField jTextField8; static JButton jButton1; static Container pae; static JFrame frm; public databaseAccess() { // super(); initComponents(); } private void initComponents() { frm = new JFrame ("Database Information"); //Create frame frm.setSize(400,400); //Set size to 400x400 pixels pae = frm.getContentPane(); //Get content pane pae.setLayout(null); //Apply null layout //frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Close when X is clicked jButton1 = new javax.swing.JButton(); jTextField5=new JTextField(); jTextField6=new JTextField(); jTextField7=new JTextField(); jTextField8=new JPasswordField(); jTextField1=new JLabel("Enter database name here"); jTextField2=new JLabel("Enter table name"); jTextField3=new JLabel("Enter user name"); jTextField4=new JLabel("Enter password"); jButton1=new JButton("Enter"); // setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); frm.add(jTextField1); frm.add(jTextField2); frm.add(jTextField3); frm.add(jTextField4); frm.add(jTextField5); frm.add(jTextField6) ; frm.add(jTextField7); frm.add(jTextField8); frm.add(jButton1); jTextField1.setBounds(20,20,150,30); jTextField2.setBounds(20,60,150,30); jTextField3.setBounds(20,100,150,30); jTextField4.setBounds(20,140,150,30); jTextField5.setBounds(200,20,150,30); jTextField6.setBounds(200,60,150,30); jTextField7.setBounds(200,100,150,30); jTextField8.setBounds(200,140,150,30); jButton1.setBounds(80,230,100,60); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { String database="",table="",user="",password=""; database=jTextField5.getText(); table=jTextField6.getText(); user=jTextField7.getText(); password=jTextField8.getText(); //connecting with JDBC Connection m_Connection = null; Statement m_Statement = null; ResultSet m_ResultSet = null; String m_Driver ="com.mysql.jdbc.Driver"; String m_Url = "jdbc:mysql://localhost:3306/"; m_Url+=database; //Loading driver try { Class.forName(m_Driver); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } String query = ""; try { FileWriter fstream = new FileWriter("D:/database.txt"); BufferedWriter out = new BufferedWriter(fstream); //Create connection object m_Connection = DriverManager.getConnection(m_Url, user, password); //Create Statement object m_Statement = m_Connection.createStatement(); query = "SELECT * FROM "; query+=table; //Execute the query m_ResultSet = m_Statement.executeQuery(query); String s,t=""; //Loop through the results // while (m_ResultSet.next()) { if(m_ResultSet.next()){ s=m_ResultSet.getString(1); t+=s; }out.write(t); //}//end for while loop out.close(); } catch (SQLException ex) { ex.printStackTrace(); System.out.println(query); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } finally { try { if (m_ResultSet != null) m_ResultSet.close(); if (m_Statement != null) m_Statement.close(); if (m_Connection != null) m_Connection.close(); } catch (SQLException ex) { ex.printStackTrace(); } } frm.dispose(); } }); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frm.setVisible(true); }// end of initcomponents() }//end of class databaseaccess
See here...I have got two string value in two values named 'Database' and 'table'
Java Code:public class Compare extends javax.swing.JFrame { public compare(){ System.out.println(database); System.out.println(table); } }
This is my problem...
I need to access the database and table in this class compare.
How to do this???
Please help me....
Similar Threads
-
inheritence questions
By mac in forum New To JavaReplies: 1Last Post: 04-05-2010, 11:54 PM -
please explain multiple inheritence by an example lot of tutorial i checked but not
By javastuden in forum New To JavaReplies: 1Last Post: 02-08-2010, 02:57 PM -
Getting around inheritence
By nick2price in forum New To JavaReplies: 3Last Post: 01-18-2009, 07:48 AM -
How to get objects to interact without inheritence in separate classes?
By Fliz in forum New To JavaReplies: 1Last Post: 11-18-2008, 05:48 PM -
[SOLVED] Problem with code - inheritence
By yalla in forum New To JavaReplies: 1Last Post: 03-30-2008, 07:11 AM
Bookmarks