为了账号安全,请及时绑定邮箱和手机立即绑定

报错SQL类

package jdbc;


import java.sql.DriverManager;

import java.sql.SQLException;


import com.mysql.jdbc.Connection;

import com.mysql.jdbc.ResultSet;

import com.mysql.jdbc.Statement;



public class Test {

private static final String URL="jdbc:mysql://127.0.0.1:3306/imooc";

private static final String USER="root";

private static final String PASSWORD="123456";

private static java.sql.Connection conn= null;

static {

try {

Class.forName("com.mysql.jdbc.Driver");

 conn = DriverManager.getConnection(URL,USER,PASSWORD);

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static java.sql.Connection getconnection(){

return conn;

}

public static void main(String[] args) throws Exception{

java.sql.Statement stm =conn.createStatement();

     //Statement stm =(Statement) conn.createStatement();

      ResultSet rs=(ResultSet) stm.executeQuery("select user_name,age from imooc_goddess");

          while(rs.next()){

         System.out.println(rs.getString("user_name")+"  "+rs.getInt("age"));

         

          }


}

}



package dao;


import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;


import com.mysql.jdbc.Connection;

import com.mysql.jdbc.ResultSet;

import com.mysql.jdbc.Statement;


import jdbc.Test;

import mode.Goddess;


public class goddessdap {


public void add(){

}

public void Update(){

}

public void del(){

}

public  List<Goddess> qurel() throws SQLException{

java.sql.Connection conn = Test.getconnection();

java.sql.Statement stm = conn.createStatement();

      ResultSet rs=(ResultSet) stm.executeQuery("select user_name,age from imooc_goddess");

      List<Goddess> gs = new ArrayList<Goddess>();

      Goddess g= null;

     

      while(rs.next()){

       System.out.println(rs.getString("user_name")+"  "+rs.getInt("age"));

        g= new Goddess();

      g.setUser_name(rs.getString("user_name"));

      g.setAge(rs.getInt("age"));

      gs.add(g);

        }

return gs;

}

public Goddess qurel2(){

return null;

}

}



package Contral;


import java.sql.SQLException;

import java.util.List;


import dao.goddessdap;

import mode.Goddess;


public class Contral {


public static void main(String[] args) throws SQLException {

goddessdap g=  new goddessdap();

List <Goddess> gsk = g.qurel();

for (Goddess goddess : gsk) {

System.out.println("goddess.getUser_name()"+",goddess.getAge()");

}

}

}



http://img1.sycdn.imooc.com//56138cff000101b813660746.jpg


求指教!!!!!!!!!!!!!!!!!!!!!


正在回答

举报

0/150
提交
取消

报错SQL类

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信