TA的每日心情 | 擦汗 2017-4-28 09:37 |
---|
签到天数: 8 天 连续签到: 1 天 [LV.3]测试连长
|
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DataBaseConnetc {
public static String stringQuery (String ip ,String table ,String conclum ,String username,String password,String querySql) throws SQLException, ClassNotFoundException{
Class.forName("com.mysql.jdbc.Driver");
Connection con = null;
String url = "jdbc:mysql://"+ip+":3306/"+table+"?useUnicode=true&characterEncoding"
+"=ISO-8859-1";
con=DriverManager.getConnection(url,username,password);
Statement sql=con.createStatement();
ResultSet resultSet=sql.executeQuery(querySql);
String str1=null;
while(resultSet.next()){
str1=resultSet.getString(conclum); //需要什么类型字段就填什么
}
sql.close();
con.close();
return str1;
}
} |
|