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

package com.itbaizhan;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * blob类型操作测试类
 */
public class BlobTest {
    /**
     * 向Movie表中插入数据
     */
    public void insertMovie(String moviename, InputStream is){
        Connection connection = null;
        PreparedStatement ps = null;

        try{
            //获取连接
            connection = jdbcUtils.getConnection();
            //获取PreparedStatement对象
            ps = connection.prepareStatement("insert into movie values(default,?,?)");
            //绑定参数
            ps.setString(1,moviename);
            ps.setBlob(2,is);
            ps.executeUpdate();

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            jdbcUtils.closeResource(ps,connection);
        }

    }

    public static void main(String[] args) throws FileNotFoundException {
        BlobTest bt = new BlobTest();
        //创建读取文件的IO流
        InputStream is = new FileInputStream(new File("d:/1.jpg"));
        bt.insertMovie("战狼",is);
    }
}

image.png为什么我这样打出来会显示不了名字

JAVA 全系列/第三阶段:数据库编程/JDBC技术 1097楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 1098楼

MySQL的安装问题。

win10系统,64位,安装5.7.36版本。

再下面这幅图的一步卡住啦。(自己百度网上各种方式,还是会这样)。

image.png

log里的内容如下:

Saving my.ini configuration file...

Saved my.ini configuration file.

Ended configuration step: Writing configuration file


Beginning configuration step: Updating Windows Firewall rules


Adding a Windows Firewall rule for MySQL57 on port 3306.

Attempting to add a Windows Firewall rule with command: netsh.exe advfirewall firewall add rule name="Port 3306" protocol=TCP localport=3306 dir=in action=allow

确定。



Successfully added the Windows Firewall rule.

Ended configuration step: Updating Windows Firewall rules


Beginning configuration step: Adjusting Windows service


Attempting to grant Network Service require filesystem permissions.

Granted permissions.

Adding new service

New service added

Ended configuration step: Adjusting Windows service


Beginning configuration step: Initializing database (may take a long time)


Deleting the data directory from a previous (failed) configuration...

Attempting to run MySQL Server with --initialize-insecure option...

Starting process for MySQL Server 5.7.36...

Starting process with command: C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.7\my.ini" --console --initialize-insecure=on --lower-case-table-names=1...

2022-05-26T07:06:52.121753Z 0 [ERROR] Invalid value for named_pipe_full_access_group.

2022-05-26T07:06:52.121817Z 0 [ERROR] Aborting

Process for mysqld, with ID 12228, was run successfully and exited with code 1.

Failed to start process for MySQL Server 5.7.36.

Database initialization failed.

Ended configuration step: Initializing database (may take a long time)


JAVA 全系列/第三阶段:数据库编程/MySQL数据库 1101楼
JAVA 全系列/第三阶段:数据库编程/SQL 语言 1102楼

package com.bjsxt;

import java.sql.*;

public class JdbcText {
    //插入数据库信息
    public void insertdepartment(String department_name , int location_id){
        Connection conn=null;
        Statement state=null;
        try {
            conn = JdbcUilt.getConnection();
            String sql ="insert into departments values(default,'"+department_name+"',"+location_id+")";
            state = conn.createStatement();
            System.out.println(state.executeUpdate(sql));
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JdbcUilt.closeZong(state,conn,null);
        }
    }
    //修改数据库信息
    public void Updatedepartment(String department_name , int location_id , int department_id){
        Connection conn = null;
        Statement state = null;
        try{
            conn = JdbcUilt.getConnection();
            state = conn.createStatement();
            String sql = "update departments d set d.department_name='"+department_name+"',d.location_id="+location_id+" where d.department_id="+department_id+"";
            System.out.println(state.executeUpdate(sql));
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JdbcUilt.closeZong(state , conn,null);
        }
    }
    //创建查询方法
    public void selectdepartment(int department_id){
        Connection conn = null;
        Statement state = null;
        ResultSet rs = null;
        try{
            conn = JdbcUilt.getConnection();
            state = conn.createStatement();
            String sql = "select * from departments where department_id"+department_id;
            rs = state.executeQuery(sql);
            while (rs.next()){
                System.out.println(rs.getInt("department_id")+" "+rs.getString("department_name")+" "+rs.getInt(3));
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JdbcUilt.closeZong(state , conn,rs);
        }
    }
    public static void main(String[] args) {
        JdbcText jb = new JdbcText();
        //jb.Updatedepartment("教育部",6,6);
        jb.selectdepartment(6);
    }
}
Wed Jul 28 18:04:16 CST 2021 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.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'department_id6' in 'where clause'
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2491)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2449)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381)
	at com.bjsxt.JdbcText.selectdepartment(JdbcText.java:45)
	at com.bjsxt.JdbcText.main(JdbcText.java:59)

请问老师我这个报错怎么解决?

JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 1105楼
JAVA 全系列/第三阶段:数据库编程/SQL 语言 1106楼
JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 1107楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 1108楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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