连接mysql的字符串
2008-08-04 20:59
344 查看
连接mysql的字符串,注意使用细节。
Connection=
("jdbc:mysql://localhost:3306/dataname","root","password")
举例1:
连接字符串
MySqlConnection conn = new MySqlConnection("User Id=root;Password=sa;Host=localhost;Database=mis;");
conn.Open();
MySqlDataAdapter da = new MySqlDataAdapter("select id, name, age from `mis`.`users` ",conn);
DataSet ds = new DataSet();
da.Fill(ds,"users");
conn.Close();
DataGrid1.DataSource= ds;
DataGrid1.DataBind();
举例2:
package com;
import java.sql.*;
public class ssss {
public static void main(String args[]) {
try {
Class.forName("org.gjt.mm.mysql.Driver");
//加载MYSQL JDBC驱动程序
System.out.println("Success loading Mysql Driver!");
}
catch (Exception e) {
System.out.print("Error loading Mysql Driver!");
e.printStackTrace();
}
try {
Connection connect = DriverManager.getConnection(
"jdbc:mysql://localhost/student", "root", "123");
// 连接URL为 jdbc:mysql//服务器地址/数据库名
// 后面的2个参数分别是登陆用户名和密码
System.out.println("Success connect Mysql server!");
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from teststudent");
while (rs.next()) {
System.out.println(rs.getString("sn")+"---"+rs.getString("ss"));
}
}
catch (Exception e) {
System.out.print("get data error!");
e.printStackTrace();
}
}
}
Connection=
("jdbc:mysql://localhost:3306/dataname","root","password")
举例1:
连接字符串
MySqlConnection conn = new MySqlConnection("User Id=root;Password=sa;Host=localhost;Database=mis;");
conn.Open();
MySqlDataAdapter da = new MySqlDataAdapter("select id, name, age from `mis`.`users` ",conn);
DataSet ds = new DataSet();
da.Fill(ds,"users");
conn.Close();
DataGrid1.DataSource= ds;
DataGrid1.DataBind();
举例2:
package com;
import java.sql.*;
public class ssss {
public static void main(String args[]) {
try {
Class.forName("org.gjt.mm.mysql.Driver");
//加载MYSQL JDBC驱动程序
System.out.println("Success loading Mysql Driver!");
}
catch (Exception e) {
System.out.print("Error loading Mysql Driver!");
e.printStackTrace();
}
try {
Connection connect = DriverManager.getConnection(
"jdbc:mysql://localhost/student", "root", "123");
// 连接URL为 jdbc:mysql//服务器地址/数据库名
// 后面的2个参数分别是登陆用户名和密码
System.out.println("Success connect Mysql server!");
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from teststudent");
while (rs.next()) {
System.out.println(rs.getString("sn")+"---"+rs.getString("ss"));
}
}
catch (Exception e) {
System.out.print("get data error!");
e.printStackTrace();
}
}
}
相关文章推荐
- mysql中连接字符串操作
- 【mysql】函数内字符串连接&char to int转换
- Mysql 字符串连接
- mysql中字符串连接
- MYSQL连接字符串参数解析(解释) 分类: 数据库 2012-12-04 11:23 1084人阅读 评论(0) 收藏
- 自己如何正确获取MYSQL的ADO连接字符串
- C#/.NET连接各类主流数据库(SQL Server,MySQL,Microsoft Access,DB2,Oracle)的连接字符串整理
- 三大主流数据库加载驱动的URL及连接字符串(sqlserver,mysql,oracle)
- Oracle、MySql、SQL Server连接JDBC的字符串
- MYSQL连接字符串参数解析(解释)
- Mysql连接字符串的配置
- 使用mysql截取、连接字符串
- MySQL连接字符串总结
- MySQL中concat函数(连接字符串)
- Mysql连接字符串大全
- [数据库连接字符串] MySQL 连接字符串
- mysql连接字符串,连接字段结果集
- MYSQL连接字符串参数详细解析(大全参考)
- MySQL中concat函数(连接字符串)
- sqlserver、mysql获取连接字符串步骤