package com.imooc.db;
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
/**
* Created by Administrator on 2015/7/4.
*/
public class DBUtil {
private static final String URL="jdbc:mysql://127.0.0.1:3306/test";
private static final String NAME="root";
private static final String PASSWORD="";
public static void main(String[] args) throws Exception{
//加载数据库
Class.forName("com.mysql.jdbc.Driver");
//连接数据库
Connection conn=DriverManager.getConnection(URL,NAME,PASSWORD);
//取数
Statement stmt= (Statement) conn.createStatement();
ResultSet rs= stmt.executeQuery("select user_name,age from imooc_goddess");
while (rs.next()){
System.out.println(rs.getString("use_name")+";"+rs.getString("age"));
}
}
}
以下是错误信息:
Information:Using javac 1.8.0_45 to compile java sources
Information:java: Errors occurred while compiling module 'Java'
Information:Compilation completed with 1 error and 0 warnings in 3 sec
Information:1 error
Information:0 warnings
C:\Users\Administrator\IdeaProjects\Vin's Files\Java\src\com\imooc\db\DBUtil.java
Error:Error:line (21)java: 找不到符号
符号: 方法 executeQuery(java.lang.String)
位置: 类型为java.beans.Statement的变量 stmt