import java.sql.*;
public class ExecuteSQL {
public static void main(String args[]) throws Exception
{
/* Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://LocalHost/student?user=root&password=000";
Connection conn=DriverManager.getConnection(url);
String sql="INSET INTO stuinfo(stu_id,stu_name,sex,province) VALUES('2001','liqiag','m','guangxi')";
Statement stmt=conn.createStatement();
System.out.println("INSERT"+stmt.executeUpdate(sql));
sql="DELETE FROM stuinfo WHERE(stu_id='2001')";
System.out.println("DELETE "+stmt.executeUpdate(sql));
stmt.close();
conn.close();*/
//1.注册一个mysql驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//2.建立连接
Connection conn=DriverManager.getConnection("jdbc:mysql://LocalHost:3306/jdbc","root","000");
//3.创建语句
Statement st=conn.createStatement();
//4.执行语句
ResultSet rs=st.executeQuery("select * from user");
//5.处理结果
while(rs.next())
{
System.out.println(rs.getObject(1)+"\t"+rs.getObject(2)+"\t"+
rs.getObject(3)+"\t"+rs.getObject(4)+"\t");
}
//6.释放资源
rs.close();
st.close();
conn.close();
}
}
/*
* 1 如何加驱动,选中jdbc然后右键,打开以后properties for jdbc ,第三个选项的第三个选项卡
* add extendal jar, mysql-connection-bin。ok
* 2 在mysql当中选择LocalHost(区分大小写)
* 3 chema当中选择test
* 4 SQLException有红线,那么就import java.sql.*;
*/