package info.dyndns.oszc.Introduce;
import java.sql.*;
public class BasePlus {
public static void main(String[] args) throws Exception {
template();
}
public static void template() throws Exception {
String driver = "com.mysql.jdbc.Driver";
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String user = "oszc";
String password = "1234";
String url = "jdbc:mysql://localhost:3306/comment";
String sql = "select * from say";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url,user,password);
st = conn.createStatement();
rs = st.executeQuery(sql);
while (rs.next()){
System.out.println(rs.getObject(1)+"\t"+rs.getObject(2)+"\t"+rs.getObject(3));
}
}finally{
try{
rs.close();
}
finally{
try{
st.close();
}
finally{
conn.close();
}
}
}
}
} |
|