1.改,update
//连接信息
val onlineUrl = "jdbc:mysql://"
val username = "root"
val password = "1234"
def getOnlineConnection(): sql.Connection = {
DriverManager.getConnection(onlineUrl, username, password)
}
val conn: Connection = Tool.getOnlineConnection()
try {
conn.setAutoCommit(false)
val sql = new StringBuilder()
//在这里写你要实现得sql,?代表你得参数
.append("update table set name=?,age=? where id=?")
val pstm = conn.prepareStatement(sql.toString())
pstm.setString(1, name)
pstm.setInt(2, age)
pstm.setInt(2, id)
pstm.executeBatch()
pstm.executeUpdate() > 0
conn.commit()
}
finally {
conn.close()
}
2.查,select
val url = "jdbc:mysql://"
val driver = "com.mysql.jdbc.Driver"