code134.java

package pack04;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class code134
{
public static void main(String[] args) throws ClassNotFoundException
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","mysql123");
Statement stmt = conn.createStatement();

String sql = "select * from customer";
ResultSet rSet = stmt.executeQuery(sql);

while (rSet.next())
{
String id = rSet.getString("id");
String name = rSet.getString("name");
String job = rSet.getString("job");
String phone = rSet.getString("phone");
System.out.println("id=" + id + " name=" + name + " job=" + job + " phone=" + phone);

}
rSet.close();
stmt.close();
conn.close();

} catch (SQLException e)
{
e.printStackTrace();
}
}
}

/*
* create table customer(
id int auto_increment not null primary key,
name varchar(30) not null,
job varchar(30),
phone varchar(15)
)
insert into customer values (null,'one','teacher','110');
insert into customer values (null,'two','doctor','120');
insert into customer values (null,'three','writer','130');
*
*
*
*/