 |
 |
Developing OS X Applications using MySQL
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2002
Location: UK
Status:
Offline
|
|
I am interested in writing an application for OS X and before I start buying books on the subject I was wondering whether you can access mysql databases from Project Builder. I know I can do this using PHP and Internet Explorer, but I would like to actually write my own application.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Using the MySQL C client library.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2002
Location: UK
Status:
Offline
|
|
Thank you Angus_D ,
Now I know its possible, I'll have to buy some books - Is there any you recommend?
I know PHP quite well, have learn't Flash Actionscript (which I believe is very similar to Javascript and taught myself C+ about 10 years ago!
Basically I have created a Filemaker database for our print company and I believe I could market it as a complete application. Although I could use filemaker developer, I would prefer to write my own OS X application, using Aqua elements and also it needs to be networkable which I believe filemaker devloper applications are not.
Also it would be a good way to get into application writing as I already know what the finished application should include.
So, any good books? Do you think I'm out of my depth?
Let me know what you think.
Cheers
Rik
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
I checked out the header files a few years ago for writing a C program that accesses a mysql database although in the end i wrote everything in perl. the general idea is very similar in both languages.
you connect ot the server, sending in strings with passwords and what-have-you.
you genrate and send in a string with your query and you get back either a string with the results or some sort of obect with the results (can't remember).
you might be able to save yourself some $$$ on the books and just search google for a tutorial on how to use the header files. since you've done this before you should be able to pick up the idea pretty quick.
|
|
12" Aluminum Powerbook
1.5Ghz G4 | 512Mb Ram | GeForce FX Go5200
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
JAVA JAVA JAVA JAVA JAVA JAVA......!!!!
JDBC!
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2002
Location: UK
Status:
Offline
|
|
Kristoff,
Go on, give me some more....
I've just completed the Cocoa Java tutorial to create a temperature converter. Wow I here you say! OK not difficult and I think your right, Java looks the easiest to use.
So do you know of any Java/JDBC websites which explain setting up a Java/Mysql application?
[ 04-18-2002: Message edited by: rik1 ]
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Aug 2001
Location: Germany
Status:
Offline
|
|
Hi rik,
I've had to take the same decission as you.
I've made some programs using Delphi, MS Access and so on, but after changing to OS X I had to learn something real new.
I decided to jump over Obect C and start directly with Java and Cocoa.
The only problem is that the most sample-code and books and writen for object C and you have to transfer the code to the Jave Syntax (the classes are mostly the same).
Learning mySQL and JDBC (if you know something about SQL) is not so difficult.
Just do it like that:
1.
Create your table within mySQL or use a Application like SQL Grinder (define a primary key, otherwise the update command don't work).
2.
Get some Sample Code to make a Connection, create a Statement and open your Resultset (not the right words/classes, sorry).
3.
After that you can use this samplecode to fill your NSTableView etc.
My biggest Problem was, that the resultset I created was not updateable (because I forgot the primary key). The rest worked fine.
I hoe this will help you
Mark
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
There are plenty of reasons not to develop Cocoa using Java, there's a list somewhere. I strongly suggest learning C.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Aug 2000
Status:
Offline
|
|
i picked up every good book on mySQL by New Riders (called simply "MySQL"). As well as lots of good general (and not not so general) information, there were some really good examples on using the c headers in a custom application (command line only, but still).
There were also examples on perl/php access.
may be of use. I was thinking of developing an applescript extension to be able to access a mySQL DB. Never quite got my head round it though :-)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: ny ny usa
Status:
Offline
|
|
You could use WebObjects to build a native OSX app that uses the java client. WebObjects will connect to MySQL out of the box.
|
|
'Satisfy the urge and discover the need' Q-Tip
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by muchfresh:
<STRONG>You could use WebObjects to build a native OSX app that uses the java client. WebObjects will connect to MySQL out of the box.</STRONG>
There are issues with WO/MySQL, IIRC, and it costs $699 with no deployment license for EOF available. You might as well use JDBC if you want to use Java, but I still suggest using Obj-C (by using Cocoa you're already losing the cross-platformness of it, and if you really wanted to you could call JDBC across the Java Bridge).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2001
Location: Dundee, Scotland
Status:
Offline
|
|
DuBois by "NewRiders" is an excellent book but pricey.
Avoid the O'Reilly book at all costs - It's terrible.
Developing a MySQL application is child's play in OSX. all the tools are either their or freely available. For anything not-to-big, GCC is great, fast , simple, free. The C API is also very simple. Make sure you download the pdf manual from MySQL. It's invaluable.
Just be careful where the header and lib files are installed - then everything should be ok.
Don't resort to Fink. I just adds a layer of unportability to your code.
As for Java - I can't comment as I don't ue it.. but I've seen some fairly impressive things done with it and MySQL. I'm just not sure that it's ideal for most "small" or "tiny" projects.
C is always a "Quick Hack" even when your program is 15,000 lines long. That's the danger of it. But for something small (say a cgi) it's almost ideal.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: ny ny usa
Status:
Offline
|
|
sambeau writes:
C is always a "Quick Hack" even when your program is 15,000 lines long. That's the danger of it. But for something small (say a cgi) it's almost ideal.
Curious, please elaborate.
|
|
'Satisfy the urge and discover the need' Q-Tip
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2002
Location: UK
Status:
Offline
|
|
Thanks for all your help regarding this, although it all looks pretty complicated.
Basically I've created a system in filemaker which I think I could market. However, I want this as a standalone application, using os x aqua elements etc. Although I could do this with filemaker developer, the database needs to be accessed from many machines and I believe filemaker developer only allows one user.
I've been reading about WebObjects and this seems to be an easier step to make in terms of learning something new.
Is this the case? Can I take that next step from filemaker to developing a stand alone database application using WebObjects?
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
WO doesn't really support stand-alone database applications at the moment, especially as there is no flat-file adaptor for EOF or licensing scheme for distributing apps that use EOF. For a stand-alone DB app, you'd need to use an embedded engine type thing. Valentina?
|
|
|
| |
|
|
|
 |
|
 |
|
Registered User
Join Date: May 2001
Location: Cambridge, UK
Status:
Offline
|
|
Originally posted by sambeau:
<STRONG>DuBois by "NewRiders" is an excellent book but pricey.
C is always a "Quick Hack" even when your program is 15,000 lines long. That's the danger of it. But for something small (say a cgi) it's almost ideal.</STRONG>
I too would like this explained!
C may not be the best option for large projects, but to describe it as a "Quick Hack" seems a bit harsh.
Matt
[ 04-26-2002: Message edited by: mattcunnane ]
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2002
Location: UK
Status:
Offline
|
|
Sorry Angus, can you explain what you mean by EOF and Valentina?
|
|
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
Originally posted by rik1:
<STRONG>Kristoff,
Go on, give me some more....
I've just completed the Cocoa Java tutorial to create a temperature converter. Wow I here you say! OK not difficult and I think your right, Java looks the easiest to use.
So do you know of any Java/JDBC websites which explain setting up a Java/Mysql application?</STRONG>
What made that temperature converter tutorial was not the Java language, but rather the Cocoa frameworks, which are even easier to use if you write Objective-C instead of Java... give credit where it's due.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jun 2001
Location: Dundee, Scotland
Status:
Offline
|
|
Originally posted by mattcunnane:
<STRONG>
I too would like this explained!
C may not be the best option for large projects, but to describe it as a "Quick Hack" seems a bit harsh.
Matt
</STRONG>
Sorry I was probably being either
a) over flippant.
or
b) over cautious about advising somene to program in C as I have been flamed for it in the past.
I program almost completely in C and have a 20,000+ lines of code project on the go at the moment.
But, come on,we all know:
1. It can be difficult to build simple to use, complex reusable libraries out of it. Object orientation makes this so much simpler.
2. Memory management is a pig. No it is. I'm forever trying to free a constant string and getting into bother. There is no way to do it properly without tags. And by that time you might aswell write some basic Garbage Collection.
3. I seem to be using (void *) as my type of choice more and more. Are you?
Mind you we all know this:
1. It's very quick to type - which is important in my book.
2. Algorithms are not hidden by the code. The very conciseness of the C makes it clear what is going on. So no need for comments
3. I mainly write CGIs so I have no need to free() anything
4. It's very fast and very powerful.
5. Unix loves it. OSX loves it.
6. I love it.
Maybe it's just me that writes quick hacky C code.
*not*

|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
<IMG SRC="http://java.sun.com/images/logos/javalogo52x88.gif"">
Here is a servlet context listener that shows how to load the driver.
What it does is it puts a reference to a connection in the servlet context when the container is initialized. It uses deployment descriptors to fill in the config values.
This is just to give you an idea about how to load the driver:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
public void contextInitialized(ServletContextEvent event)
{
this.context = event.getServletContext();
String host = context.getInitParameter(<font color = red>"dbhost"</font>);
String port = context.getInitParameter(<font color = red>"dbport"</font>);
String instance = context.getInitParameter(<font color = red>"dbinstance"</font>);
String username = context.getInitParameter(<font color = red>"dbuser"</font>);
String password = context.getInitParameter(<font color = red>"dbpasswd"</font>);
String connectionURL = <font color = red>"jdbc:mysql:<font color = brown>//"</font>+host+<font color = red>":"</font>+port+<font color = red>"/"</font>+instance+<font color = red>"?user="</font>+username+<font color = red>"&password="</font>+password+<font color = red>"&autoReconnect=true"</font>;</font>
try{
Class.forName(<font color = red>"org.gjt.mm.mysql.Driver"</font>).newInstance();
Connection connection = DriverManager.getConnection(connectionURL, <font color = red>""</font>, <font color = red>""</font>);
this.context.setAttribute(<font color = red>"connection"</font>, connection);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(<font color = red>"it's happening in the init"</font>);
}
<font color = brown>//Output a simple message to the server's console</font>
System.out.println(<font color = red>"admin Is Ready: using connectionURL = "</font>+connectionURL);
}
</font>[/code]
Here is how the connection reference is used to get data (in this case).
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
Connection connection = (Connection)application.getAttribute(<font color = red>"connection"</font>);
Statement getTheClasses = connection.createStatement();
ResultSet theClasses = getTheClasses.executeQuery(<font color = red>"SELECT * FROM COURSES order by course_number"</font>);
String title = theClasses.getString(<font color = red>"title"</font>);
String units = theClasses.getString(<font color = red>"units"</font>);
String seats = theClasses.getString(<font color = red>"seats"</font>);
</font>[/code]
This is just to show you the basics.
There are obviously more complex methods.
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|