Connecting Mysql With JAVA.

By mahfuz05

for connecting mysql with java first of all need mysql java connector jconnector.

after downloading this extract it. then place it to Java\jdk1.6.0_03\jre\lib\ext .

after this start coding.

String DRIVER=”com.mysql.jdbc.Driver”;

String DATABASE_URL=”jdbc:mysql://localhost/books”;

Class.forName(JDBC_DRIVER);

con=DriverManager.getConnection(DATABASE_URL,”root”,” password”);

statement=con.createStatement();

then write your sql.
String sql=”select * from admin”;
ResultSet rs=statement.executeQuery(sql);
// this for call by name
rs.getInt(“roll”));
rs.getString(“name”));
or write
// this for call by id no
rs.getString(1)
rs.getString(2)
then play with your code.

Tags:

Leave a Reply