the field type is text
i really have no idea hope you guys can help me
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
the field type is text
i really have no idea hope you guys can help me
Last edited by A4Andy; September 5th, 2011 at 05:33 AM.
Which bit do you have no idea about - constructing a JComboBox, transferring data from resultSet to array/Vector, or retrieving data from MySQL? You should: SELECT a ResultSet from MySQL (java.sql.Connection, java.sql.Statement, java.sql.ResultSet), transfer the data you want to display to the user into an array or java.util.Vector, invoke the JComboBox constructor with the data you've collected.
transferring mysql data to array is my problem
here is the code that I'm playing with
public int i; public String [] array; PreparedStatement pstmt = con.prepareStatement("Select * from products"); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { array[i]=rs.getString(2); i++; } JComboBox combo = new JComboBox(array);
I'm getting no error but eclipse is suspends the program
highlighting (exception nullpointer exception)
array[i]=rs.getString(2);
Where do you give a value to the array variable?
You give a value to a variable by using the assignment statement:
array = ....
I change my while statement to
while(rs.next()) { array=rs.getString(2); }
but I got an error Type mismatch cannot convert from String to String[]
Last edited by A4Andy; September 5th, 2011 at 09:44 AM.
The array variable is a String[] array.
The getString() method returns a String.
You need to give the array variable a value. It is defined as String[]
You need to use the new statement to give it a String[] value.
array = new String[1]; // give the variable array a value
A4Andy (September 5th, 2011)
thanks it's already solved. I forgot the give the array a value