jsp连接数据库
package frist;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class comi {
private static final String URL="jdbc:mysql://127.0.0.1:3306/imooc";
private static final String USER="root";
private static final String PASSWORD="root";
public static void main(String[] arges) throws Exception{
//加载驱动
Class.forName("com.mysql.jdbc.Driver");
//连接数据库
java.sql.Connection conn=DriverManager.getConnection(URL,USER,PASSWORD);
//操作数据库
java.sql.Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select username,age from imooc_goddeess");
while(rs.next()){
System.out.println(rs.getString("username")+","+rs.getInt("age"));
}
}
}
Exception in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'imooc.imooc_goddeess' doesn't exist
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
at frist.comi.main(comi.java:20)