I have an sql database and i'm trying to link to it using a java bean with some sql. I'm having trouble at the moment, i thought i had cracked it with my code beolw, but i'm unable to compile the code. I get the following error for the line that i have made bold below, error:
webtech/questionaalt.java [63:1] cannot resolve symbol
symbol : variable i
location: class webtech.questionaalt
result += "<td>" + results.getObject(i).toString()+ "</td>";
^
Can anyone help????
Code:
Code:private Connection dbconn = null; public questionaalt() { try { Class.forName(driver); dbconn = DriverManager.getConnection(url, uname, dpass); /*Create an SQL statement*/ Statement statement = dbconn.createStatement(); if (statement.execute(query)) {/*Step 3) If we have a result lets loop through*/ ResultSet results = statement.getResultSet(); ResultSetMetaData metadata = results.getMetaData(); /*Validate result. Note switch to while loop if we plan on multiple results from query*/ if(results != null) { /*Use results setmetadata object to determine the columns*/ int li_columns = metadata.getColumnCount(); result = "<tr>"; for(int i = 1; i <= li_columns;i++) { result+="<td>" + metadata.getColumnLabel(i) + "</td>"; } result += "</tr>"; while (results.next()) { result +="<tr>"; for (int i=1; i <= li_columns; i++); { result += "<td>" + results.getObject(i).toString()+ "</td>"; } result += "</tr>"; } } } }




Reply With Quote