I am creating a small application that utilizes the jdbcdbc bridge to retrieve information from a database. I am new to Java and have mostly used C++ for text-based programs. Therefore, using the GUI classes is new to me. I created a JFrame that includes several JTextFields to receive input from the user. The input to JTextField tf1 will be an integer number representing the primary key of a database record. My problem is that the database views this field as a number and requires it to be a number in the sql query but the JTextField provides a String. How can I convert the String from the JTextField to a number (integer) so the database will recognize it in the SQL select statement? A snippet of the code follows. As you can see I tried casting to an int and that did not work. SearchResults is another JFrame that is called to display the results of the query. The resourceIN is the name of the number field representing the primary key in the database. Somehow I need to get the return from the JTextField tf1 into number format. Thank you for your assistance.<br>
<br>
(CODE FOR CLASS UP HERE)<br>
<br>
public void actionPerformed(ActionEvent e) {<br>
String queryString;<br>
if (e.getActionCommand().equals(CANCEL)) {<br>
setVisible(false);<br>
}<br>
else{<br>
if(e.getSource().equals(tf1)){<br>
// if (e.getActionCommand().equals(tf1)) {<br>
// String RIN = (int)tf1.getText(); DID NOT WORK<br>
queryString = "SELECT resources.resourceIN," +<br>
"resources.title, resources.location, " + <br>
"resources.available "<br>
+ "FROM resources WHERE "<br>
// + "resources.resourceIN = '" + RIN + "'"; (DIDN'T <br>
// WORK) <br>
+ "resources.resourceIN = '" + tf1.getText() + "'"; <br>
/*<br>
queryString = "SELECT resources.resourceIN, resources.title," + " resources.location, resources.available "<br>
+ "FROM resources";<br>
*/ <br>
searchResults = new SearchResults("Library System "<br>
+ "-- Search Results", queryString); <br>
searchResults.pack();<br>
searchResults.setVisible(true);<br>
setVisible(false); <br>
}<br>
else{<br>
(MORE CODE FROM HERE)<br>
<br>
(CODE FOR CLASS UP HERE)<br>
<br>
public void actionPerformed(ActionEvent e) {<br>
String queryString;<br>
if (e.getActionCommand().equals(CANCEL)) {<br>
setVisible(false);<br>
}<br>
else{<br>
if(e.getSource().equals(tf1)){<br>
// if (e.getActionCommand().equals(tf1)) {<br>
// String RIN = (int)tf1.getText(); DID NOT WORK<br>
queryString = "SELECT resources.resourceIN," +<br>
"resources.title, resources.location, " + <br>
"resources.available "<br>
+ "FROM resources WHERE "<br>
// + "resources.resourceIN = '" + RIN + "'"; (DIDN'T <br>
// WORK) <br>
+ "resources.resourceIN = '" + tf1.getText() + "'"; <br>
/*<br>
queryString = "SELECT resources.resourceIN, resources.title," + " resources.location, resources.available "<br>
+ "FROM resources";<br>
*/ <br>
searchResults = new SearchResults("Library System "<br>
+ "-- Search Results", queryString); <br>
searchResults.pack();<br>
searchResults.setVisible(true);<br>
setVisible(false); <br>
}<br>
else{<br>
(MORE CODE FROM HERE)<br>