Monday, June 22, 2009

MySQL Connection using Java

show databases; //display database name
create database database-name; //create database
use database-name; //use database
show tables from database-name; //show tables
show columns from table-name; //show colums
drop database database-name; //drop database

java syntax to connect to database

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql:///shop","root","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from item_master where category_name='"+cname+"' ");

here shop is db name of my jsp project

Author : Anuj Patel

Blog : http://goldenpackagebyanuj.blogspot.in/