1.检测web应用中的连接配置
2.写个简单的Main类来测试下package com.mysql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Mysql {
public static void main(String[] args) {
Connection conn = null;
try {
String userName = "root";
String password = "111111";
String jdbcurl = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(jdbcurl, userName, password);
String sql = "select id,name,status from test";
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
String result = "";
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
int status = rs.getInt("status");
result += id + "\t" + name + "\t" + status + "\n";
}
System.out.println(result);
pstmt.close();
} catch (Exception e) {
System.err.println("Cannot connect to database server,Exception:"
+ e.getMessage());
} finally {
if (conn != null) {
try {
conn.close();
conn = null;
} catch (Exception e) { /* ignore close errors */
}
}
}
}
}