关于“java与mysql数据库的连接”

来源:百度知道 编辑:UC知道 时间:2024/07/06 11:56:20
java与数据库的连接中url名称分为了三部分,jdbc:mysql:,之后是子名称,这个子名称我一直没弄明白。有同事用过jdba:mysql://localhost:3306/databasename,我现在要在tomact下连接,loaclhost是不是要改成127.0.0.1,另外这个端口号是怎么查到的?我还不知道这个端口号3306是怎么来的。请大家指正下

安装 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")