关于“java与mysql数据库的连接”
来源:百度知道 编辑:UC知道 时间:2024/07/06 11:56:20
安装 mysql 时 有一个文本框 默认端口是 3306
这个端口是可以修改的,开始--程序--mysql--配置mysqlXXXX的菜单,是一个可视化的配置界面。
loaclhost 127.0.0.1 都行的通。
下面是一个小例子
import java.io.*;
import java.sql.*;
/**
*在mysql数据库里成功测试,并且发现mysql的blob数据库不支持存储图片,只支持65535字节以下的本本数据存储。
*/
public class InsertBlobInMysql {
public static void main(String[] args) {
try {
File f = new File("C:\\bsmain_runtime.log");
long length = f.length();
FileInputStream fis = new FileInputStream("C:\\bsmain_runtime.log");
byte[] imageBytes = new byte[(int) length];
int byteLength = fis.read(imageBytes, 0, (int) length);
ByteArrayInputStream bais = new ByteArrayInputStream(imageBytes);
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/test", "root", "12345")