2018. 3. 12. 10:15
[ColdFusion] DSN 없이 DB에 접속하는 방법
2018. 3. 12. 10:15 in 팁&테크/Coldfusion & Lucee
//Load the database driver using java class loader classLoader = createObject("java", "java.lang.Class"); classLoader.forName("com.mysql.jdbc.Driver"); //Create a driver manager instance driverManager = createObject("java","java sql.DriverManager"); //Create the connection to the DB connection = driverManager.getConnection("jdbc:mysql://localhost:3306/demodb?user=demouser&password=demopass"); //Create a connection statement and run our query string statement = connection.createStatement(); resultSet = statement.ExecuteQuery("SELECT * FROM testtable"); //Convert the resultset into a coldfusion query object queryObj = createObject("java", "coldfusion sql.QueryTable").init(resultSet); //Close the connection connection.Close();