package mysqltest;/**
 * 通过sql语句对数据库增、删、改、查
 */
import java.sql.*;
import java.lang.Exception;public class MySqlJdbcTest {

/**
 * 创建数据库表的sql语句
 */
private static final String EMPLOYEE_TABLE="create table MyEployees(id int primary key,"+
"firstNmae varchar(20),lastName varchar(20),title varchar(20),salary int)";
/**
 * 创建数据库的Connection对象
 */
public static Connection getConnection() throws Exception{
//驱动程序
String driver="org.gjt.mm.mysql.Driver";
//数据库地址
String url="jdbc:mysql://localhost/test";
String username="root";
String password="123456";
//加载驱动器
Class.forName(driver);
//建立连接
Connection conn=DriverManager.getConnection(url,username,password);
return conn;
}
/**
 * 遍历结果集,并打印
 */

/**
 * @param rs 结果集
 */
public static void printData(ResultSet rs)throws Exception{
//处理结果集
while(rs.next()){
String firstName=rs.getString(2);
String lastName=rs.getString(3);
System.out.println("name="+firstName+lastName);
}
}
public static void main(String[] args) {
Connection conn=null;
Statement stmt=null;
try{
//得到数据库连接
conn=getConnection();
//通过Statement创建数据库表
System.out.print("Cretat table_____");
stmt.executeUpdate(EMPLOYEE_TABLE);
//为表MyEmployees插入2条记录
stmt.executeUpdate("insert into MyEmployees(id,firstName,lastName) values(100,'cheng','.boo')");
stmt.executeUpdate("insert into MyEmployees(id,firstName,lastName) values(200,'zhang','.yanLin')");
ResultSet rs=stmt.executeQuery("Select * form MyEmployees");

//打印结果
printData(rs);
}catch(ClassNotFoundException e){
System.out.print("error: failed to load MySql driver");
e.printStackTrace();
}catch(SQLException e){
System.out.print("error: failed to create a connection object.");
}catch(Exception e){
System.out.print("other error.");
e.printStackTrace();
}finally{
try{
//释放Statement和Connnection
//stmt.close();
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
} }}运行时产生错误:
Cretat table_____
other error.java.lang.NullPointerException
at mysqltext.MySqlJdbcTest.main(MySqlJdbcTest.java:57)
-----
57 行代码:stmt.executeUpdate(EMPLOYEE_TABLE);   是哪里产生的异常?  我怎么看也没有问题嘛。