scala 代码
import java.sql.{DriverManager, Connection, ResultSet}
object hello {
val user="root"
val password = "password"
val host="yourip"
val database="yourdb"
val conn_str = "jdbc:mysql://"+host +":3306/"+database+"?user="+user+"&password=" + password
println(conn_str)
def main(args:Array[String]): Unit ={
//classOf[com.mysql.jdbc.Driver]
Class.forName("com.mysql.jdbc.Driver").newInstance();
val conn = DriverManager.getConnection(conn_str)
println("hello")
try {
// Configure to be Read Only
val statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)
// Execute Query
val rs = statement.executeQuery("SHOW TABLES")
// Iterate Over ResultSet
while (rs.next) {
println(rs.getRow())
}
}
catch {
case _ : Exception => println("===>")
}
finally {
conn.close
}
}
}
sbt代码
```name := "test"
version := "1.0"
organization :="com.timger.info"
version :="0.0.1-SNAPSHOT"
exportJars := true
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.33"
resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
### 执行
sbt run
```
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。