package com.JDBC;
import java.sql.*;
public class TestDML {
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
try{
//加载MySql的驱动类
Class.forName("com.mysql.jdbc.Driver") ;
}catch(ClassNotFoundException e){
System.out.println("找不到驱动程序类 ,加载驱动失败!");
e.printStackTrace() ;
}
try {
conn = DriverManager
.getConnection("jdbc:mysql://localhost/webbuy?user=zyb&password=930105");
stmt = conn.createStatement();
String sql = "insert into goods values ('potato',2.4)";
stmt.executeUpdate(sql);
}catch(SQLException ex){
}finally {
try {
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}