import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class JDBC
{
public static void main(String[] args)
{
connection conn = null ;
PreparedStatement ps = null ;
try{
class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lsj","root","333");
String sql = "insert into dept(deptno,dname,loc) values(?,?,?)";
ps = conn.prepareStatement(sql);
ps.setInt(1,60);
ps.setString(2,"销售部");
ps.setString(3,"上海");
int count = ps.executeUpdate();
System.out.println(count);
}catch(Exception e)
{
e.printStackTrace();
}finally{
if(ps != null)
{
try{
ps.close();
}catch(SQLException e){
e.printStackTrace();
}
}
if(conn != null)
{
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
}
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class JDBC
{
public static void main(String[] args)
{
connection conn = null ;
PreparedStatement ps = null ;
try{
class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lsj","root","333");
String sql = "update dept set dname = ? , loc = ? where deptno = ?";
ps = conn.prepareStatement(sql);
ps.setString(1,"研发一部");
ps.setString(2,"北京");
ps.setInt(3,60);
int count = ps.executeUpdate();
System.out.println(count);
}catch(Exception e)
{
e.printStackTrace();
}finally{
if(ps != null)
{
try{
ps.close();
}catch(SQLException e){
e.printStackTrace();
}
}
if(conn != null)
{
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
}
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class JDBC
{
public static void main(String[] args)
{
connection conn = null ;
PreparedStatement ps = null ;
try{
class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lsj","root","333");
String sql = "delete from dept where deptno = ?";
ps = conn.prepareStatement(sql);
ps.setInt(1,60);
int count = ps.executeUpdate();
System.out.println(count);
}catch(Exception e)
{
e.printStackTrace();
}finally{
if(ps != null)
{
try{
ps.close();
}catch(SQLException e){
e.printStackTrace();
}
}
if(conn != null)
{
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
}