import com.mysql.jdbc.jdbc2.optional.MysqlDataSource
import com.mysql.jdbc.*
import groovy.sql.*
/* the commented code works fine
MysqlDataSource ds = new MysqlDataSource()
ds.user = 'root'
ds.password = ""
ds.url = 'jdbc:mysql://localhost:3306/test'
Sql sql=Sql.newInstance(ds)
sql.close()
*/
d=Class.forName("com.mysql.jdbc.Driver").newInstance()
println d.class // class com.mysql.jdbc.Driver
Sql sql=Sql.newInstance(
'jdbc:mysql://localhost:3306/test',
'root',
"",
'com.mysql.jdbc.Driver'
)
注释的代码工作正常,我可以得到驱动程序的实例
但是当我使用的时候
Sql sql=Sql.newInstance(
'jdbc:mysql://localhost:3306/test',
'root',
"",
'com.mysql.jdbc.Driver'
)
它引发了一个异常:
java.sql.SQLException:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / test
我无法解决它,是否有任何男孩来帮助我?