I am new to play frame work and i am finding it bit difficult. i am retrieving list of client names from data base and populating it to a dropdown ,here is my client.java code
package models;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import play.db.ebean.Model;
public class Client extends Model {
/**
*
*/
private static final long serialVersionUID = -1932214701504374792L;
public static String ClientName;
public static ArrayList<String> Clientdetail= new ArrayList<>();
public static ArrayList<String> PopulateClient() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433","SUMEET","sumeet");
Statement sta = conn.createStatement();
String Sql = "select * from client";
ResultSet rs = sta.executeQuery(Sql);
while (rs.next()) {
ClientName = rs.getString("ClientName");
Clientdetail.add(ClientName);
}
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException |SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return(Clientdetail);
}
}
Here is My application.java code
package controllers;
import models.Client;
import play.mvc.*;
import views.html.*;
public class Application extends Controller {
public static Result index(){
return ok(index.render(Client.PopulateClient()));
}
}
and here is my index.scala.html
@(ClientDetails: java.util.ArrayList[String])
@main("ADMS") {
<center>
<form id="select">
<a>CONSULTANT</a>
<select name=Consultant>
<option value="lokesh">Lokesh</option>
<option>@ClientDetails</option>
<option>Vidyasekar</option>
<option>Abhishek</option>
<option>Naveen</option>
<option>Nanda</option>
</select>
<table border="1">
<tr>
<td width=50px>Client</td>
<td width=50px>Project</td>
<td width=50px>Task</td>
<td width=50px>Date</td>
<td width=50px>Consultant</td>
<td width=50px>Role</td>
<td width=80px>Is Billable</td>
</tr>
<tr>
<td>@ClientDetails</td>
</tr>
</table>
</form>
</center>
}
main.scala.html
@(title: String)(Content: Html)
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
</head>
<body>
@Content
</body>
</html>
Can some one help me with this? i need to populate the dropdown with the array value and the data that is getting populated is just brackets --> "[]"