?
Solved

MySQL ODBC 3.51 Driver Database Connection

Posted on 2011-04-21
4
Medium Priority
?
558 Views
Last Modified: 2012-06-22
Hi,

I want to connect to my MySQL database and display all records in my database.
Can anyone help me.

<cfscript>

classLoader = createObject("java", "java.lang.Class");
classLoader.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dm = createObject("java","java.sql.DriverManager");

con = dm.getConnection("jdbc:odbc:DRIVER={MySQL ODBC 3.51 Driver}; SERVER=xxx; PORT=xxx; DATABASE=xxx; USER=xxx; PASSWORD=xxx; OPTION=16;");

st = con.createStatement();
 
</cfscript>

<cfquery name="getFromDynamicConnection" datasource="st">
  Select * FROM CustLogin
</cfquery>

I am not sure how to do this!!!!!!


Thanks,
0
Comment
Question by:lulu50
  • 3
4 Comments
 
LVL 53

Expert Comment

by:_agx_
ID: 35441485
<cfquery name="getFromDynamicConnection" datasource="st">

The best way is to create a datasource in the CF Administrator first. Then you can run any query by using the datasource name in your cfquery tags.


classLoader = createObject("java", "java.lang.Class");

CF does not support dynamic datasources. While you can connect to a db *without* creating a  datasource .. I wouldn't recommend it.  It's more complex and error prone. Also, JDBC (not ODBC) is generally the preferred connection type.

0
 
LVL 53

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 35441510
Here's an entry on creating a datasource in CF. It's very simple.

Setting up a datasource in Coldfusion Administrator
http://www.pukkared.com/2010/03/setting-up-a-datasource-in-coldfusion-administrator/
0
 

Author Comment

by:lulu50
ID: 35441682
agx,
I already setup my ODBC from the host control panel. the connection is fine right now but I
want to dump or display my data from my table.
how would I do this.


<cfscript>

classLoader = createObject("java", "java.lang.Class");
classLoader.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dm = createObject("java","java.sql.DriverManager");

con = dm.getConnection("jdbc:odbc:DRIVER={MySQL ODBC 3.51 Driver}; SERVER=xxx; PORT=xxx; DATABASE=xxx; USER=xxx; PASSWORD=xxx; OPTION=16;");

st = con.createStatement();
rs = st.ExecuteQuery("Select * FROM CustLogin");
q = createObject("java", "coldfusion.sql.QueryTable").init(rs);

how can I do this I need to dump my data
dump(var=#q#);

rs.close();
st.close();
con.close();

</cfscript>
0
 
LVL 53

Expert Comment

by:_agx_
ID: 35442035
> I already setup my ODBC from the host control panel

I guess what I'm asking is - is there a reason why are you not using a CF datasource? The normal way of connecting to a db in CF is a lot simpler than what you're doing.  With a CF datasource you don't need any of that code. Just use your datasource name in a cfquery tag.

ie
<cfquery name="getData" datasource="yourCFDatasourceName">
     SELECT ColA, ColB FROM SomeTableName
</cfquery>

Then to output the information, use <cfoutput>

ie
<cfoutput query="getData">
    #ColA#  |  #ColB# <br>
</cfoutput>

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question