会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132382个问题

数据已经添加,但是有报错,查不到报错原因:

运行报错

Mon Jul 15 12:54:15 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

1

代码

package cn.bjsxt.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;



public class JdbcTest {
	//向Departments表中添加一条数据
	public void insertDepartments(String department_name,int location_id ){
		//注册驱动
		Connection conn = null;
		Statement state = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			//创建连接
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bjsxt?useUnicode=true&characterEncoding=utf-8","root","123456");
			String sql="insert into departments values(default,'"+department_name+"',"+location_id+")" ;
			state = conn.createStatement();
			int flag = state.executeUpdate(sql);
			System.out.println(flag);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(state!=null){
				try {
					state.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(conn!=null){
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	public static void main(String [] args){
		JdbcTest test = new JdbcTest();
		test.insertDepartments("研发部",8);
	}

}


JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 36887楼
Python 全系列/第三阶段:Python 网络与并发编程/网络通信 36888楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 36889楼

  1. 代码部分没有报错,运行结果显示错误。

  2. cuo.gif

  3. 所对应GameUtil代码

  4. package cn.lss.Game;
    import java.awt.Image;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    
    public class GameUtil {
    	//工具类最好将构造器私有化
    	private GameUtil() {
    		
    	}
    	public static Image getImage(String path) {
    		BufferedImage bi = null;
    		try {
    			URL u = GameUtil.class.getClassLoader().getResource(path);
    			bi = ImageIO.read(u);
    		}catch (IOException e) {
    			e.printStackTrace();
    		}
    		return bi;
    	}
    
    }
  5. 现在执行代码

  6. package cn.lss.Game;
    
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    import javax.swing.JFrame;
    import javax.swing.WindowConstants;
    
    /**
     * 飞机游戏的主窗口
     * @author 李帅帅
     *
     */
    public class MyGameFrame extends JFrame{
    	Image plane = GameUtil.getImage("images/plane.png");
    	Image bg = GameUtil.getImage("images/bg.pg");
    	@Override
    	public void paint(Graphics g) {
    		g.drawImage(bg, 0,0, null);
    		g.drawImage(plane, 200,200, null);
    	}
    	/**
    	 * 初始化窗口
    	 */
    	public void launchFrame() {
    		this.setTitle("尚学堂学员_李帅帅作品");
    		this.setVisible(true);
    		this.setSize(400,400);
    		this.setLocation(300, 300);
    	this.addWindowListener(new WindowAdapter() {
    		@Override
    		public void windowClosing(WindowEvent e) {
    			System.exit(0);
    		}
    	});
    			}
    	public static void main(String[]args) {
    		MyGameFrame f = new MyGameFrame();
    		f.launchFrame();
    	}
    
    }

JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 36892楼

  1. 代码

  2. package cn.lss.Game;
    
    import java.awt.Graphics;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    import javax.swing.JFrame;
    import javax.swing.WindowConstants;
    
    /**
     * 飞机游戏的主窗口
     * @author 李帅帅
     *
     */
    public class MyGameFrame extends JFrame{
    	@Override
    	public void paint(Graphics g) {
    		// TODO Auto-generated method stub
    		super.paint(g);
    	}
    	/**
    	 * 初始化窗口
    	 */
    	public void launchFrame() {
    		this.setTitle("尚学堂学员_李帅帅作品");
    		this.setVisible(true);
    		this.setSize(400,400);
    		this.setLocation(300, 300);
    	this.addWindowListener(new WindowAdapter() {
    		@Override
    		public void windowClosing(WindowEvent e) {
    			System.exit(0);
    		}
    	});
    			}
    	public static void main(String[]args) {
    		MyGameFrame f = new MyGameFrame();
    		f.launchFrame();
    	}
    
    }
  3. 运行无问题1.gif

  4. 代码

  5. package cn.lss.Game;
    
    import java.awt.Graphics;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    import javax.swing.JFrame;
    import javax.swing.WindowConstants;
    
    /**
     * 飞机游戏的主窗口
     * @author 李帅帅
     *
     */
    public class MyGameFrame extends JFrame{
    	@Override
    	public void paint(Graphics g) {
    		g.drawRect(100, 100, 200, 200);
    	}
    	/**
    	 * 初始化窗口
    	 */
    	public void launchFrame() {
    		this.setTitle("尚学堂学员_李帅帅作品");
    		this.setVisible(true);
    		this.setSize(400,400);
    		this.setLocation(300, 300);
    	this.addWindowListener(new WindowAdapter() {
    		@Override
    		public void windowClosing(WindowEvent e) {
    			System.exit(0);
    		}
    	});
    			}
    	public static void main(String[]args) {
    		MyGameFrame f = new MyGameFrame();
    		f.launchFrame();
    	}
    
    }
  6. 在窗口中画东西,显示黑屏,是电脑配置原因吗?2.gif


JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 36894楼
Python 全系列/第七阶段:网页编程基础/jquery 36897楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/手写服务器项目(旧) 36898楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637