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();
}
}
}