Results 1 to 2 of 2

Thread: Connecting MySql with connector/J from Java

  1. #1
    mega's Avatar
    mega is offline Newbie Net Builder
    Join Date
    May 2009
    Location
    Hell , Wanna Come ??
    Posts
    62
    Thanks
    0
    Thanked 10 Times in 4 Posts

    Red face

    Mysql is a very popular open source database used today.Even it also support enterprise usage.

    It was mostly used with php scripting language on web development.

    When it time it need to be used with java .
    How to configure it ?, how to connect to it ?
    Here is quick start.

    <a href="http://ipost2host.com/viewtopic.php?f=13&t=2411#" target="_blank">
    </a>
    Code:
    import java.lang.*;
    import java.sql.*;
    import com.mysql.jdbc.SQLError;
    
    package org.fluxionbt;
    
    public class program
    {
       public static void main(String[] args)
       {
           // load the mysql jdbc driver, it is an implementation of Driver interface.
           Class.forName("com.mysql.jdbc.Driver");
           Connection conn = null;
           Statement stmt = null;
           ResultSet rs = null;
    
          // create a connection to the mysql database server, select default database and send name and password
           conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "user1", "pasword1");
    
          // create a statement object for execute sql command.
          // There are some addition options availabel. Check out sdk for more information.
           stmt = conn.createStatement();
           rs = stmt.executeQuery("SELECT * FROM sample");
    
           while (rs.next())
           {
              // print out the field data. You can also use index-based to obtain data in the table fields.
               System.out.println(rs.getString("username"));
           }
       }
    }
    Never argue with an idiot; First he takes you down to his level and then he beats you with experience.

  2. #2
    ghadeer is offline Net Builder
    Join Date
    Oct 2009
    Posts
    108
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks very much for sharing
    realy its very usefull

Similar Threads

  1. what java can do?
    By garfish in forum Web Design
    Replies: 27
    Last Post: 26 July, 2012, 02:15 AM
  2. Replies: 4
    Last Post: 23 January, 2010, 09:52 AM
  3. Java-Script
    By Marcell Purham in forum Programming
    Replies: 2
    Last Post: 15 July, 2009, 07:20 AM
  4. Replies: 4
    Last Post: 21 June, 2009, 07:33 AM
  5. more than 3000 java script files
    By ghadeer in forum Programming
    Replies: 0
    Last Post: 9 May, 2009, 00:02 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •