Search code examples
sql-serverscaladatabase-connectionresultset

Change ResultSet to TYPE_SCROLL_INSENSITIVE in Scala


I'm using Scala to connect to a database. The connection is working and I can execute SQL with the output stored in a ResultSet. I now need to change the ResultSet to TYPE_SCROLL_INSENSITIVE so that I can point to specific rows in the ResultSet. This is a section of my code (connection details omitted for data privacy):

import java.sql.{Connection, ResultSet, SQLException, Statement}

object test extends App {

def connectURL (): java.sql. Connection  = {

val url  =  "connection url"
val username =  sys.env.get("USER").get    
val password =  sys.env.get("PASS").get

 
Class. forName ( "driver name" ) 
var connection = java.sql.DriverManager. getConnection ( url ,  username ,  password )
     connection  
}

val query = "SELECT * FROM TABLE1"

val con : java.sql. Connection  =  connectURL (); // creates the connection
val st  =  con . createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE); // creates connection statement
val rs  =  st.executeQuery(query); // executes the query and stores as ResultsSet 

}

This gives the error: overloaded method value createStatement

The con variable is of type Connection, st is of type Statement and rs is of type ResultSet. I've tried changing val to the types above, and I get this error: value st is not a member of object java.sql.Statement

Any help would be much appreciated.


Solution

  • Please see javadocs https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html createStatement is defined with either 0,2, or 3 parameters