This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes Newbie Java MySql question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Newbie Java MySql question" Watch "Newbie Java MySql question" New topic
Author

Newbie Java MySql question

Scott Matthews
Ranch Hand

Joined: Jun 28, 2001
Posts: 36
I am new to java (about 6 months). I downloaded the MySql and am running the Server (MySqlD) on my Win98 computer. I can run MySql and all works fine when I input commands by hand. I want to now create a java program that will open an existing database and insert some records.
Can anyone provide a quick source code snippet that would handle opening a database and "sending" the database a SQL statement?

Thanks for your time.
Dorj Galaa
Ranch Hand

Joined: May 29, 2001
Posts: 113
import java.sql.*;
import org.gjt.mm.mysql.Statement;
public class MySQL
{
public static void main(String args[])
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection mysql=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/ecom?user=username&password=password");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
download MySQL jdbc driver http://mmmysql.sourceforge.net


Senior software engineer
 
GeeCON Prague 2014
 
subject: Newbie Java MySql question