什么版本的JDBC支持MySQL5.1.41,可以将Java连接MySQL的代码贴出来吗

Agile牧 2009-12-04 11:17:05
如题,还有最新版本的可视化MySQL是哪个,可以将具体的使用JDBC驱动Java连接MySQL的具体操作具体流程说一下
...全文
193 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2009-12-04
  • 打赏
  • 举报
回复
[Quote]什么版本的JDBC支持MySQL5.1.41[/Quote]

http://dev.mysql.com/downloads/connector/j/5.1.html


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

Connection conn = null;
...
try {
conn =
DriverManager.getConnection("jdbc:mysql://localhost/test?" +
"user=monty&password=greatsqldb");

// Do something with the Connection

...
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}




官方手册中就有例子。

21.4.3. Connector/J Examples
Examples of using Connector/J are located throughout this document, this section provides a summary and links to these examples.

Example 21.1, “Connector/J: Obtaining a connection from the DriverManager”

Example 21.2, “Connector/J: Using java.sql.Statement to execute a SELECT query”

Example 21.3, “Connector/J: Calling Stored Procedures”

Example 21.4, “Connector/J: Using Connection.prepareCall()”

Example 21.5, “Connector/J: Registering output parameters”

Example 21.6, “Connector/J: Setting CallableStatement input parameters”

Example 21.7, “Connector/J: Retrieving results and output parameter values”

Example 21.8, “Connector/J: Retrieving AUTO_INCREMENT column values using Statement.getGeneratedKeys()”

Example 21.9, “Connector/J: Retrieving AUTO_INCREMENT column values using SELECT LAST_INSERT_ID()”

Example 21.10, “Connector/J: Retrieving AUTO_INCREMENT column values in Updatable ResultSets”

Example 21.11, “Connector/J: Using a connection pool with a J2EE application server”

Example 21.12, “Connector/J: Example of transaction with retry logic”

wwwwb 2009-12-04
  • 打赏
  • 举报
回复
图形化管理工具:SQLYOG不错
wwwwb 2009-12-04
  • 打赏
  • 举报
回复
什么版本的JDBC支持MySQL5.1.41
Connector/J 5.1
http://dev.mysql.com/downloads/connector/j/5.1.html
ACMAIN_CHM 2009-12-04
  • 打赏
  • 举报
回复
[Quote]新版本的可视化MySQL是哪个[/Quote]

没有可视化MySQL,MYSQL只是个数据库管理系统。没有人机界面。
你需要的GUI管理工具可以到官网下载。
http://dev.mysql.com/downloads/gui-tools/5.0.html
wwwwb 2009-12-04
  • 打赏
  • 举报
回复
可以将Java连接MySQL的代码贴出来吗
Import java.sql.*;

public class SampleIntro
{
public static void main(String[] args)
{
try
{
Connection conn;
Statement stmt;
ResultSet res;
//加载Connector/J驱动
//这一句也可写为:Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.jdbc.Driver").newInstance();
//建立到MySQL的连接
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root", "guapo");
//执行SQL语句
stmt = conn.createStatement();
res = stmt.executeQuery("select * from pet");
//处理结果集
while (res.next())
{
String name = res.getString("name");
System.out.println(name);
}
res.close();

}
catch (Exception ex)
{
System.out.println("Error : " + ex.toString());
}
}
}

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧