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="jdbc:odbc: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
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.
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