Results 1 to 3 of 3
  1. #1
    naipulb is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default Java program that transfers stock prices to MySQL database

    Hi

    Jag want to bring stock prices from csv files (excel) on the internet and copy them to a MySQL database through a Java program. I have downloaded the following:

    -Eclipse
    -MySQL server 5.0
    -MySQL Connector/J

    With this installed I should be able to edit mySQL databases through JDBC, but I don't know so much more. Can somebody help me to get started?

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Can somebody help me to get started?
    have some tutorials about it first....

    sukatoa

  3. #3
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    You will need to create a new Java project in Eclipse. Once complete, right click the project in the Package window and click 'Properties' Then navigate to 'Java Build Path' Click 'Add JARs' and locate the MySQL JDBC driver. Add it and click OK..

    Then you can use this code to connect to the database:

    Java Code:
       import java.sql.*;
    
       public class Connect
       {
           public static void main (String[] args)
           {
               Connection conn = null;
    
               try
               {
                   String userName = "testuser";
                   String password = "testpass";
                   String url = "jdbc:mysql://localhost/test";
                   Class.forName ("com.mysql.jdbc.Driver").newInstance ();
                   conn = DriverManager.getConnection (url, userName, password);
                   System.out.println ("Database connection established");
               }
               catch (Exception e)
               {
                   System.err.println ("Cannot connect to database server");
               }
               finally
               {
                   if (conn != null)
                   {
                       try
                       {
                           conn.close ();
                           System.out.println ("Database connection terminated");
                       }
                       catch (Exception e) { /* ignore close errors */ }
                   }
               }
           }
       }
    Did this post help you? Please me! :cool:

Similar Threads

  1. problem in connecting to mysql database
    By nancyv in forum Java Servlet
    Replies: 6
    Last Post: 04-02-2008, 11:33 AM
  2. Replies: 0
    Last Post: 03-29-2008, 03:36 PM
  3. Help needed with updating mysql database
    By SilentCodingOne in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 10:23 PM
  4. Replies: 0
    Last Post: 10-04-2007, 09:33 PM
  5. connecting to mysql database
    By javagal in forum NetBeans
    Replies: 2
    Last Post: 08-04-2007, 12:36 PM

Posting Permissions

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