meget mærkeligt... det virker ca. hver 10. gang jeg prøver...
Min JSP ser således ud (hat taget uvedkommende ud):
<%@ page language="java" import="java.util.*, helperClasses.*"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<title>Create new delivery</title>
</head>
<body bgcolor="white">
<html:errors/>
<html:form action="/CreateDeliveryAction">
Select the customer company:<BR>
<html:select property="customerCompanyName" size="1">
<%
//listCustomerCompanies lcc = new listCustomerCompanies()
ArrayList lst = listCustomerCompanies.getCustomerCompaniesList();
for(int i=0;i<lst.size();i++)
{
%>
<option><%=lst.get(i)%></option>
<%
}
%>
</html:select><BR><BR>
<html:submit property="submit" value="Save delivery"/>
</html:form>
</td>
</tr>
</table>
</body>
</html:html>
Og min klasse ser således ud
package helperClasses;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
import java.util.*;
public class listDeliveries
{
private static Connection con = null;
private static Statement stmt = null;
private static ResultSet rs = null;
public listDeliveries(){}
public static void getConnection()
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:
mysql://localhost/deliveryinterview?user=root&password=jokl98ac");
}
catch (SQLException sex)
{
// handle any errors
System.out.println("SQLException: " + sex.getMessage());
System.out.println("SQLState: " + sex.getSQLState());
System.out.println("VendorError: " + sex.getErrorCode());
}
catch (Exception ex)
{
System.out.println("Exception: " + ex.getMessage());
}
}
public static ResultSet getDeliveries()
{
try
{
stmt = con.createStatement();
StringBuffer sqlString = new StringBuffer("SELECT delivery_name FROM deliveries");
rs = stmt.executeQuery(sqlString.toString());
}
catch (SQLException sex)
{
// handle any errors
System.out.println("SQLException: " + sex.getMessage());
System.out.println("SQLState: " + sex.getSQLState());
System.out.println("VendorError: " + sex.getErrorCode());
}
return rs;
}
public static ArrayList getDeliveriesList()
{
ArrayList l = new ArrayList();
try
{
getDeliveries();
int i = 0;
while(rs.next())
{
String element = rs.getString(1);
l.add(element);
i++;
}
}
catch (SQLException sex)
{
// handle any errors
System.out.println("SQLException: " + sex.getMessage());
System.out.println("SQLState: " + sex.getSQLState());
System.out.println("VendorError: " + sex.getErrorCode());
}
return l;
}
}
Kan i se, hvad der sker? Eller rettere hvorfor den nogle gange kører og andre ange ikke?