jdbc连接数据库
来源:互联网 发布:郑州大学软件学院 一本 编辑:程序博客网 时间:2024/05/29 09:26
package testdb;
import java.sql.*;
public class TestDb {
public static void main(String[] args) {
String strDBDriver="com.mysql.jdbc.Driver";
String strDBUrl="jdbc:mysql://localhost:3306/test";
try {
Class.forName(strDBDriver).newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection conn = null;
try {
conn = DriverManager.getConnection(strDBUrl,"root","root");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//创建数据库连接对象
Statement stmt = null;
try {
stmt = conn.createStatement();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String sql="select count(*) as num from i_s_logon";
try {
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.println("num="+rs.getInt("num"));
//System.out.println("password="+rs.getString("password"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.sql.*;
public class TestDb {
public static void main(String[] args) {
String strDBDriver="com.mysql.jdbc.Driver";
String strDBUrl="jdbc:mysql://localhost:3306/test";
try {
Class.forName(strDBDriver).newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection conn = null;
try {
conn = DriverManager.getConnection(strDBUrl,"root","root");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//创建数据库连接对象
Statement stmt = null;
try {
stmt = conn.createStatement();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String sql="select count(*) as num from i_s_logon";
try {
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.println("num="+rs.getInt("num"));
//System.out.println("password="+rs.getString("password"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
0 0
- jdbc入门、jdbc连接数据库
- jdbc-odbc连接数据库
- JDBC连接MySQL数据库
- JDBC连接MySQL数据库
- JDBC之连接数据库
- [JDBC] 如何连接数据库
- JDBC连接数据库技巧
- jdbc连接数据库
- JDBC连接常用数据库
- jdbc连接数据库
- JDBC连接SqlServer2005数据库
- jdbc连接各种数据库
- JDBC连接各种数据库
- JDBC连接数据库参考
- JDBC连接数据库
- JDBC连接数据库小结
- JDBC连接MYSQL数据库
- Jdbc 连接数据库 实例
- Codeforces Round #354 (Div. 2) E - The Last Fight Between Human and AI
- 我和我的小伙伴们
- Mysql 插入、更新与删除数据
- Android 打印输出16进制数据
- 从0到1(上)
- jdbc连接数据库
- safari地址栏无法使用百度搜索
- JavaScript五子棋
- 页面跳转(pop返回多个ViewController)
- 大数据下的TopK算法
- 不可多得的Javascript(AJAX)开发工具 - Aptana
- [NOIP] [最短路] [SPFA] NOIP2012Junior 文化之旅 (culture)
- MySql MESSAGE: java.net.ConnectException: Connection refuse
- Mysql 查询数据