java代码连接数据库url怎么获取(java链接数据库连接地址详解)

java代码连接数据库url怎么获取(java链接数据库连接地址详解),第1张

都有统一的格式的,如下:

MicrosoftSQLServerJDBCDriver(一般用来连接SQLServer2000)

驱动程序包名:msbasejarmssqlserverjarmsutiljar

驱动程序类名:commicrosoftjdbcsqlserver

JDBCURL:jdbc:microsoft:sqlserver://:

默认端口1433,如果服务器使用默认端口则port可以省略

MicrosoftSQLServer2005JDBCDriver

驱动程序包名:sqljdbcjar

驱动程序类名:commicrosoftsqlserverjdbc

JDBCURL:jdbc:sqlserver://:

默认端口1433,如果服务器使用默认端口则port可以省略

Oracle

OracleThinJDBCDriver

驱动程序包名:ojdbc14jar

驱动程序类名:Oraclejdbcdriver

JDBCURL:

jdbc:oracle:thin:@//:/ServiceName

jdbc:oracle:thin:@::

使用宝塔面板,您可以快速地创建一个FTP管理账户,对网站文件进行管理。但有必要提醒大家的是,使用FTP远不如使用SFTP安全,你可以查看文章“FTP与SFTP有什么区别”进一步了解两者之间的差异。

此外,宝塔面板的文件管理模块其实已经能够满足站长的大部分文件管理需求。当然,如果你非得要使用FTP管理服务器文件,可以参照以下教程:

FTP管理,主要用于管理和创建FTP账号。然后你还需要借助FTP工具,比如Xshell或者FileZilla,进行连接登陆管理。

添加FTP

输入以下参数,点击提交即可创建成功。

用户名:FTP账号名称。

密码:默认随机生成密码,可以自行更改。

根目录:选择FTP目录地址,默认为>

解决方法一:

1、打开myini文件,找到default-storage-engine=InnoDB这一行,把它改成default-storage-engine=MyISAM;

2、删除在MySQL安装目录下的Data目录中的ib_logfile0和ib_logfile1;

3、找到在配置MySQL服务器时指定的InfoDB目录删除掉ibdata1

根据myini文件中:# INNODB Specific options innodb_data_home_dir="D:/";

4、重新启动MySQL的Service。

解决方法二:

把windows目录下,myini文件删除,重装mysql,服务启动成功。

1、首先配置mysql连接时,加上:nullCatalogMeansCurrent=true。

2、其次在MySQLmyini或者mycnf文件的[mysqld]下面添加一行:lower_case_table_names=1。

3、最后重启MySQL。

package dao;

/

数据库连接

/

import javasqlConnection;

import javasqlDriverManager;

import javasqlPreparedStatement;

import javasqlResultSet;

/

@author RainKylin

/

public class DBConnection {

public static Connection getConnection()

{

Connection conn = null;

try {

// 加载驱动

ClassforName("orggjtmmmysqlDriver");

String url = "jdbc:mysql://localhost:3306/webdbuser=softuseUnicode=true&characterEncoding=utf8";

//webdb是数据库名字

// 获取数据库连接

conn = DriverManagergetConnection(url, "root", "123456");

//root是登陆数据库的名字,123456是登陆数据库的密码

} catch (Exception e) {

eprintStackTrace();

}

return conn;

}

public static void closeConn(ResultSet rs, PreparedStatement pstmt,Connection conn) //关闭数据库连接

{

try {

if (rs != null)

rsclose();

if (pstmt != null)

pstmtclose();

if (conn != null)

connclose();

} catch (Exception e) {

eprintStackTrace();

}

}

}

//前面的是数据库的链接,下面一段是用于数据库的添加、修改、删除、修改

//添加学生信息

public int insertStudent(Student stu) {

// 获取数据库连接

Connection conn = DBConnectiongetConnection();

int result = 0;

PreparedStatement pstmt = null;

String sql = "insert into student values(,,,,,,,,)";

try {

pstmt = connprepareStatement(sql);

pstmtsetString(1, stugetStuId());

pstmtsetString(2, stugetStuName());

pstmtsetInt(3, stugetStuAge());

pstmtsetString(4, stugetStuSex());

pstmtsetString(5, stugetStuCollegue());

pstmtsetString(6, stugetStuProfession());

pstmtsetString(7, stugetStuClass());

pstmtsetString(8, stugetStuHobby());

pstmtsetString(9, stugetStuResume());

result = pstmtexecuteUpdate();

} catch (Exception e) {

eprintStackTrace();

} finally {

// 关闭数据库连接

DBConnectioncloseConn(null, pstmt, conn);

}

// 返回数据库受影响的行数

return result;

}

}

//删除数据

public int deleteStudent(String Id)

{

// 获取数据库连接

Connection conn = DBConnectiongetConnection();

int result = 0;

PreparedStatement pstmt = null;

String sql = "delete from student where stuId = ";

try {

pstmt = connprepareStatement(sql);

pstmtsetString(1, Id);

result = pstmtexecuteUpdate();

} catch (Exception e) {

eprintStackTrace();

} finally {

// 关闭数据库连接

DBConnectioncloseConn(null, pstmt, conn);

}

// 返回数据库受影响的行数

return result;

}

//修改学生信息

public int updateStudent(Student stu) {

Connection conn = null;

int result = 0;

PreparedStatement pstmt = null;

try {

conn = DBConnectiongetConnection();

String sql = "update student set stuName = ,stuAge = ,stuSex = ,stuCollegue = , stuProfession = , stuClass = ,stuHobby = ,stuResume = where stuId=";

pstmt = connprepareStatement(sql);

pstmtsetString(1, stugetStuName());

pstmtsetInt(2, stugetStuAge());

pstmtsetString(3, stugetStuSex());

pstmtsetString(4, stugetStuCollegue());

pstmtsetString(5, stugetStuProfession());

pstmtsetString(6, stugetStuClass());

pstmtsetString(7, stugetStuHobby());

pstmtsetString(8, stugetStuResume());

pstmtsetString(9, stugetStuId());

result = pstmtexecuteUpdate();

Systemoutprintln(result);

} catch (Exception e) {

eprintStackTrace();

} finally {

DBConnectioncloseConn(null, pstmt, conn);

}

// 返回数据库受影响的行数

return result;

}

//查询所有学生

public List<Student> seleteStudent() {

Connection conn = DBConnectiongetConnection();

//Vector<Vector<String>> data = new Vector<Vector<String>> ();

List<Student> students = new LinkedList<Student>();

PreparedStatement pstmt = null;

ResultSet rs = null;

String sql = "select stuID,stuName,stuAge,stuSex,stuCollegue,stuProfession,stuClass,stuHobby,stuResume from student";

try {

pstmt = connprepareStatement(sql);

rs = pstmtexecuteQuery();

// 获取rs中数据的列数

//int col = rsgetMetaData()getColumnCount();

// 将rs的数据封装到向量中

while (rsnext()) {

Student student = new Student();

//for (int i = 1; i <= col; i++) {

studentsetStuId(rsgetString(1));

studentsetStuName(rsgetString(2));

studentsetStuAge(rsgetInt(3));

studentsetStuSex(rsgetString(4));

studentsetStuCollegue(rsgetString(5));

studentsetStuProfession(rsgetString(6));

studentsetStuClass(rsgetString(7));

studentsetStuHobby(rsgetString(8));

studentsetStuResume(rsgetString(9));

//}

studentsadd(student);

}

} catch (Exception e) {

eprintStackTrace();

}

return students;

}

要用的时候就直接条用就OK拉

以上就是关于java代码连接数据库url怎么获取(java链接数据库连接地址详解)全部的内容,包括:java代码连接数据库url怎么获取(java链接数据库连接地址详解)、宝塔里的ftp是什么意思、宝塔mysql数据库不启动 紧急求助和解决方法等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10154362.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存