File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie Java MySql question

 
Scott Matthews
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic