Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: connection of jdbc with mysql

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default connection of jdbc with mysql

    hi
    can anyone explian me how to connect jdbc in mysql??
    i created 1 application which is not conecting to database.

    import java.sql.*;
    public class MYSQLDEMO {


    public static void main(String[] args) throws SQLException,ClassNotFoundException{
    String driverClass="sun.jdbc.odbc.JdbcOdbcDriver";
    String url="jdbcdbc:msqldsn";
    String user="root";
    String password="test";
    Class.forName(driverClass);
    Connection con=DriverManager.getConnection(url,user,password) ;
    Statement st=con.createStatement();
    String sql="insert into student values(23,nit,45)";
    st.executeUpdate(sql);
    System.out.println("query executed");
    con.close();

    }

    }
    after running this it is showing like this

    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknow n Source)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at MYSQLDEMO.main(MYSQLDEMO.java:11)


    thankyou


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: connection of jdbc with mysql

    You left off the starting lines of the error message that says what the problem is.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: connection of jdbc with mysql

    if you want to connect with mysql
    1> downdload mysql jconnector.
    2> driver class = com.mysql.jdbc.Driver".
    3> url = jdbc:mysql://your pc ip address (or localhost)/db
    4>db = database name which you want to connect

Similar Threads

  1. JDBC Too Many Connection Error
    By sajithgsm in forum JDBC & Databases
    Replies: 1
    Last Post: February 22nd, 2012, 05:08 AM
  2. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Java Servlet
    Replies: 2
    Last Post: November 21st, 2011, 11:54 PM
  3. jdbc connection problem
    By sny in forum JDBC & Databases
    Replies: 11
    Last Post: January 6th, 2011, 04:39 AM
  4. JDBC connection error
    By nrao in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 11th, 2010, 12:43 PM
  5. jdbc connection with phpmyadmin
    By anand_fevi in forum JDBC & Databases
    Replies: 1
    Last Post: May 13th, 2010, 02:26 AM