#2568 Open a SQL connection and run a query Issue

JohnNuccio Wed 12 Oct 2016

I am trying to open a SQL connection and run a query to get some data from one of the tables in that database. But so far I am having issues creating a SQL connection. Also does anyone have an example of creating a charting object with domkit from a SQL query?

using sql

class DBConnect{
Void main(){	
try {
	Str host := "jdbc:mysql://000.000.0.000"
	Str uName := "Username is here"
	Str uPass := "Password is here"

	db := SqlConn.open( host, uName, uPass)

}
catch ( SqlErr err ){
	echo( err.msg )
}
  }
     }

ERROR Message Below

WARNING: Cannot preload JDBC driver: com.mysql.jdbc.Driver No suitable driver found for jdbc:mysql://192.168.9.150

SlimerDude Wed 12 Oct 2016

Have you copied the MySql driver jar to your Fantom environment and updated etc/sql/config.props?

The steps are outlined in the sql documentation:

http://fantom.org/doc/sql/index#connections

JohnNuccio Wed 12 Oct 2016

I changed jdbc:mysql: to jdbc:sqlserver: and that seemed to fix the issue. Thanks for your help though SlimerDude

using sql

class DBConnect {
Void main(){


try {
	Str host := "jdbc:sqlserver://000.000.0.000:0000;databaseName=Something"
	Str uName := "Username"
	Str uPass := "Password"

	db := SqlConn.open( host, uName, uPass)

	echo(db.meta())

}
	//SqlErr == SQLException
catch ( SqlErr err ){
	echo( err.msg )
}
 }
}

Login or Signup to reply.