score:1
You need to declare rset
outside of your try-block:
ResultSet rset = null;
try {
String userName = "data";
String password = "data";
String url = "jdbc:mysql://localhost/playdb";
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(url, userName, password);
Statement stmt = con.createStatement();
System.out.println("Connected database successfully...");
String strSelect = "select * from computer";
//statement.setString(1, name);
rset = stmt.executeQuery(strSelect);
while(rset.next()) { // Move the cursor to the next row
String name = rset.getString("name");
int id = rset.getInt("id");
System.out.println( name + ", " + id);
// ++rowCount;
}
}
catch(SQLException e) {
e.printStackTrace();
System.out.println("cant Connected database successfully...");
}
Form<Computer> computerForm = form(Computer.class);
return ok(
createForm.render(computerForm,rset)
);
This solution is not really pretty, because if an SQL-Exception occurs, rset
will be null and you will run into troubles in your template (NullPinterException
). You might want to consider to move your return statement at the end of the try-block and add another one into the catch block for error handling.
score:0
Basically you can pass any java object to the template. Play framework has type-checking on views so you would have to declare the rset. If you look at the computer-database sample that comes with Play, you'll see it passes a Page object and three strings:
@(currentPage: com.avaje.ebean.Page[Computer], currentSortBy: String, currentOrder: String, currentFilter: String)
However, you may find it easier to copy the values from rset into your computerForm object, or another POJO, and pass that to the template.
Source: stackoverflow.com
Related Query
- how to pass sql array values from java controller to scala template
- How to pass implicit vals defined through package objects from Scala in Java
- How to pass Scala enumeration from Java
- How can I transform a numeric Scala array to be an array of intervals of the values from array?
- How do I remove duplicate values from my Multidimensional array in a Scala way?
- how to access values from a array column in scala dataframe
- how to take 2 values from array and put it as pair and set count to 1 map function in scala
- How to pass a 2 dimensional string array from java code to scala.html in play framework?
- How to get Scala List from Java List?
- How to pass Scala array into Scala vararg method?
- How to show scala doc from Java Editor in Eclipse?
- Scala 2.10 reflection, how do I extract the field values from a case class, i.e. field list from case class
- How to use Scala varargs from Java code
- How to pass Scala Seq to a Java varargs
- How to call main method of a Scala program from the main method of a java program?
- How to create a Row from a List or Array in Spark using Scala
- How to access a Java static method from Scala given a type alias for that class it resides in
- How to refer to protected inner class in Scala when inheriting from Java (with byte code only)
- How to pass a class object from Scala to Java?
- How to pass flash data from controller to view with Play! framework
- How do I convert a Java byte array into a Scala byte array?
- How to declare scala method so that it can be called from Java using varargs style
- How can I select a non-sequential subset elements from an array using Scala and Spark?
- how to pass a String* scala vararg to a java method using Scala 2.8
- Accessing boolean values from application.conf in a scala template
- How to create a Scala parallel collection from a Java collection
- How to call java method taking parameter as List<Class<?>> from Scala
- How to pass optional parameter to scala template in play framework 2
- How to convert scala Array to Java array []
- Using Scala array from java
More Query from same tag
- How to fill a ListBuffer[ List[Any] ] (Scala)?
- Type alias for inferred type
- Importing scala sbt project to Scala IDE build of Eclipse SDK
- LUB of List of Invariant Class's Instances
- How to replace epoch column in DataFrame with date in scala
- Is it possible to use absolute component positioning in Scala/Swing?
- Scala Add elements to set only by checking specific fields of a case class
- Change Flyway resources location for scala unit test
- Is it possible to declare return type for closure?
- SBT Build Fails for Scalaz library
- Is there a `OneOf` class for grouping classes with no common ancestor
- Swallowing Exception within Scala Future Method Chain
- Why scala can't pass a function name directly to a val?
- Spark DataFrame not respecting schema and considering everything as String
- Why is iterating through flattened iterator slow?
- Debugging an sbt build that doesn't see any tests
- Compare key and values in json string using scala
- IntelliJ IDEA 12.0 Scala worksheet errors under Standard User account but works under Administrator
- How do I make a Scala project "Import from git"able in Eclipse?
- Scala Akka NullPointerException error
- Scala Parser Combinators - consume until match
- How not to count space as a char using foldLeft
- Using pattern matching with Specs2 and Play in Scala
- How to specify indentations on multiline parameter lists in IntelliJ Scala?
- Unique id for Scala object
- Converting Scala @suspendable Method into a Future
- Splitting a stream in a functional way
- How to test arguments to a case class constructor?
- SparkSQL groupby to create nested records
- Scala: Using span with modular arithmetic