Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-05-2008, 04:41 PM
Member
 
Join Date: Mar 2008
Posts: 20
themburu is on a distinguished road
how to take query results to a jlist!!
Hi I do know if Im doing the right thing but I am returning my queries to a JList in my MySQL databse editor GUI prg but its not working how do you achieve this and by the way do you use a JList??
__________________
The dream of being a legend has just begun!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-07-2008, 12:51 PM
Member
 
Join Date: Mar 2008
Posts: 20
themburu is on a distinguished road
the code
here's ma code its from netbeans.

Code:
/*first i'm using two Jbuttons, *the first buttons reads the selected database to connect to from a JComboBox; 1 being MySql * it thus retrives the username, passwd and database to connect and executes the connection * *the second is to run the entered queries but for development purposes I have had to define a standard query *this query should return results as shown in previous thread but now in a JTextArea called myans. */ private void mycActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mycActionPerformed String myname = new String(""+ uname.getText()) ; String mypasswd = new String(""+ passwd.getText()) ; String mydb = new String(""+ dbname.getText()) ; //Ceck if the username has been provided if (myname!=""){ //parameters to connect to the database int chos = mychoices.getSelectedIndex(); if (chos == 1){ try { String driver = "com.mysql.jdbc.Driver"; Class.forName(driver); String url = "jdbc:mysql://localhost/"+mydb; java.sql.DriverManager.getConnection( url, myname, mypasswd ); } catch( Exception x ) { x.printStackTrace(); } } else if (chos == 2){ JOptionPane.showMessageDialog(this,"You are not allowed to connect to PostgeSQL","Configuration Error",JOptionPane.ERROR_MESSAGE); } else if (chos == 3){ JOptionPane.showMessageDialog(this,"You are not allowed to connect to Oracle","Configuration Error",JOptionPane.ERROR_MESSAGE); } } //If no username show error! else if (myname == ""){ JOptionPane.showMessageDialog(this,"Please give atlease a user name","ENTRY PROBLEM!",JOptionPane.ERROR_MESSAGE); } } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed myans.setText("Here comes the results \n"); StringBuffer message = new StringBuffer(""); Connection conn = null; Statement stmt = null; try{ //StringBuffer message = new StringBuffer(""); stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT name, owner FROM pet"); //ResultSetMetaData metaData = resultSet.getMetaData(); //int numberOfColumns = metaData.getColumnCount(); ResultSetMetaData metaData = rs.getMetaData(); int numberOfColumns = metaData.getColumnCount(); myans.setText("Column count is :" + numberOfColumns +"\n"); /* while ( rs.next() ) { for ( int i = 1; i <= numberOfColumns; i++ ) myans.setText("Column count is :" + rs.getObject(i) +"\n"); //message.append(rs.getObject(i)); //message.append("\n"); }*/ while (rs.next()) { //String entry = rs.getString(1); String s = rs.getString("name"); message.append(s); String f = rs.getString("owner"); message.append(f); } String hdss = message.toString(); myans.append(hdss); //myans.setText(hdss); } catch (SQLException e) { e.printStackTrace(); System.exit( 1 ); } finally // ensure statement and connection are closed properly { try { stmt.close(); conn.close(); } // end try catch ( Exception exception ) { exception.printStackTrace(); System.exit( 1 ); } // end catch } // end finally }
i've also tried to make sure that the username is not null and give an error message, I've used if with !="" and !=null but none works.

For the Jtextarea i've even tried StringBuffer.
So pls help me.
__________________
The dream of being a legend has just begun!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
showing results in a for loop randomly vexity New To Java 4 04-29-2008 06:24 AM
Returning multiple results (JDBC 3.0) JavaForums Java Blogs 0 04-18-2008 05:20 PM
date and calender not getting the right results valoyivd New To Java 4 04-14-2008 01:51 PM
BigInteger remainder results in zero perito New To Java 1 03-21-2008 06:07 PM
results to code disappear too fast for DOS window dubdubdub New To Java 3 12-29-2007 07:07 PM


All times are GMT +3. The time now is 01:41 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org