会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132431个问题
Python 全系列/第二阶段:Python 深入与提高/文件处理 18512楼

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

public class JDBCTest1 {
    public void insertDepartment(int department_id,String department_name,int manager_id,int location_id){
        Connection connection=null;
        Statement state = null;
        try {
            Class.forName("oracle.jdbc.OracleDriver");
            String url="idbc:oracle:thin:localhost:1521:OCLPDB";
            String username="hr";
            String psw="1234";
            Connection conn=DriverManager.getConnection(url, username, psw);
            String sql = "insert into departments values("+department_id+","+department_name+","+manager_id+","+location_id+")";
            state = connection.createStatement();
            int flat = state.executeUpdate(sql);
            System.out.println(flat);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (state!=null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (connection!=null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    public static void main(String args[]){
        JDBCTest1 j = new JDBCTest1();
        j.insertDepartment(2,"学习部",0,0);
    }
}

老师,为什么连接不上


image.png

image.png

JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 18513楼
Python 全系列/第一阶段:Python入门/编程基本概念 18515楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 18519楼

package array.src.com.itbaizhan;
import java.util.Scanner;
public class TestCalculator {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("***********我的第一个计算器************");
        System.out.println("1.输入88,系统退出程序\n2.输入66,计算下一年薪");

        while (true){
            System.out.println("请输入月薪");
            int monthSalary = sc.nextInt();
            System.out.println("请输入一年几个月薪资");
            int months = sc.nextInt();
            int yearSalary =  monthSalary*months;
            System.out.println("你的年薪为:"+yearSalary);
        }
        if(yearSalary>=200000){
            System.out.println("恭喜你超越98%的人");
        }else if (yearSalary>100000){
            System.out.println("恭喜你超越90%的人");
        }

        System.out.println("******输入88,系统退出,输入66,继续计算******");
        int comm =sc.nextInt();
        if (comm==88){
            System.out.println("计算结束,退出程序 ");
            break;
        }if (comm==66){
            System.out.println("计算下一年薪");
            continue;
        }
    }
}

老师,请问这个怎么运行不出来呢,我觉得没问题啊


错误是: break和continue在 switch 或 loop 外部中断。

还有


找不到yearSalary符号。


JAVA 全系列/第一阶段:JAVA 快速入门/控制语句、方法、递归算法 18523楼
JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 18524楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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