Created
October 13, 2017 04:01
-
-
Save bohdanszymanik/c36cda7f39348502e9f3a6b56e231063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.* | |
data class eProgProv(val AcaProg: String, val ProvName: String) | |
val eProgProvs = mutableListOf<eProgProv>() | |
fun inserteProgProv(cn: Connection, e: eProgProv ) { | |
val writeStmt = cn.createStatement() | |
fun escStr(s:String) = s.replace("'", "''") | |
var str = """insert into eAcademicProgrammeProvider (AcaProg, ProvName) | |
values ('${escStr(e.AcaProg)}', '${escStr(e.ProvName)}')""" | |
// println(str) | |
writeStmt.execute(str) | |
} | |
fun main(args: Array<String>) { | |
// conn = DriverManager.getConnection("jdbc:jtds:sybase://somesybaseserver:5000/somedb",connectionProps) // if we used Properties... | |
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance() | |
var eA8Conn: Connection? = null | |
e8Conn = DriverManager.getConnection("jdbc:jtds:sybase://somesybaseserver:5000/somedb", "someusername", "somepassword") | |
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance() | |
var sqr8Conn: Connection = DriverManager.getConnection("jdbc:sqlserver://somesqlserver:1433;databaseName=someotherdb", "someotherusername", "someotherpassword") | |
val readStmt = e8Conn.createStatement() | |
val rs = readStmt.executeQuery(""" select some big long joined up query """) | |
while (rs.next()) { | |
eProgProvs.add(eProgProv(AcaProg = rs.getString("title"), ProvName = rs.getString("surname") )) | |
} | |
// println(eProgProvs.count()) | |
eProgProvs.forEach({i -> | |
// eProgProvs.forEach({i:eProgProv -> // optionally specify type | |
//println("${i::class.qualifiedName}") // type reflection seems a little limited? or am I missing something -> "eProgProv" (and nothing else) | |
// println("${i::class}") // hmm - hardly any better -> "class eProgProv" | |
inserteQAProgProv(sqr8Conn, i) | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment