MySql help Request


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: MySql help Request

  1. #1
    Join Date
    Aug 2005
    Posts
    41

    MySql help Request

    Hi everyone,

    I need some help using java and mysql. Has anyone heard and used MySql??

    I have downloaded and installed the MySql server and created a small database file called t1 (just as a test file). It has one table in it. I have also downloaded a file from the MySql website call a MySql connector for Java. I extracted the files in the MySql directory. But I don't know what to do next. There is a file called MySql-connector-java-3.1.10-bin.jar.

    How do I use the MySql server and it databases in a Java program? I have used a Microsoft Access database with a java program. I remember having to go to the windows ODBC Data Source Administrator and add a User DSN for the database file that I wanted to use. I tried doing that but unsuccessfully. MySql wasn't in the list to choose from.

    I really need help here. I posted messages at the MySql site but no one has replied.

    Richard

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    Can't really help you with Java, but did you happen to take a look at the documentation?

    http://dev.mysql.com/doc/mysql/en/java-connector.html
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  3. #3
    Join Date
    Aug 2005
    Posts
    41

    Thanks

    Thanks for your reply but do you know where to set tht CLASSPATH so that I can have access to the driver from any directory.

  4. #4
    Join Date
    Aug 2005
    Posts
    6
    copy that .jar file in to ur jre and paste it inside

    /jre<version>/lib/ext/


    after this u can access the database using jdbc

  5. #5
    Join Date
    Aug 2005
    Posts
    41

    Thanks

    Thanks for your help but i am still doing something wrong here. I did what you said to do but it still doesn't work. I get a runtime error SQL Error: java.sql.SQLException: No suitable driver 0 08001

    Here is the code I am running:

    import java.sql.*;

    public class mysqldatabasetest1 {
    public static void main(String[] arguments) {
    String data = "jdbc:mysql:t1";

    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection(
    data, "", "");
    Statement st = conn.createStatement();
    ResultSet rec = st.executeQuery(
    "SELECT * " +
    "FROM male ");
    while(rec.next()) {
    int n = 1;
    System.out.println(rec.getString(++n) + "\t"
    + rec.getString(++n) + "\t"
    + rec.getString(++n));
    }

    st.close();
    } catch (SQLException s) {
    System.out.println("SQL Error: " + s.toString() + " "
    + s.getErrorCode() + " " + s.getSQLState());
    } catch (Exception e) {
    System.out.println(" Error: " + e.toString()
    + e.getMessage());
    }
    }
    }

    Something is still wrong. Please go through the code.
    Thanks

  6. #6
    Join Date
    Aug 2005
    Posts
    6
    String data = "jdbc:mysql://<ip address >:<port no>t1";

    ip address-the ip address of the machine where u hve ur database if u are in a network

    port no-the port no in which mysql is running--if u hvnt assigned any port no
    the default no will be-3306



    if u r not in a network

    the try using

    String data = "jdbc:mysql://localhost:3306/t1";


    -----------------------------------------------

    now the second thing is

    Connection conn = DriverManager.getConnection(
    data, "<your my sql userid>", "<password>");

    if u r loging in the database as administrator

    then

    Connection conn = DriverManager.getConnection(
    data, "root", "<password>");

    try this .....sometimes this will solve the problem


    ------------------------------------------------

    vsorc-

  7. #7
    Join Date
    Aug 2005
    Posts
    41

    finally working

    I un-installed all of my java components, deleted all of the java directories and then downloaded and installed the latest jdk 5. Then I followed what vsorc suggested to do and it worked. Thanks vsorc for your help. I am using a gui windows application to write my java code (JCreator) and it is working fine now.

    Now I just have to be able to make it work from the command line. I am having troubles I think I need to set the path to the java and javac executables because I can't use them from the current directory where the program resides. How do you do this? I thought I knew how but I guess not.

Similar Threads

  1. Xindice query
    By nonolap in forum XML
    Replies: 0
    Last Post: 05-26-2005, 04:10 AM
  2. Date/Time Data Type
    By felix in forum ASP.NET
    Replies: 2
    Last Post: 04-05-2002, 05:01 AM
  3. Replies: 0
    Last Post: 02-26-2002, 10:17 AM
  4. ui for service request tracking system - ideas
    By John Wood in forum Architecture and Design
    Replies: 1
    Last Post: 07-02-2001, 06:24 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center