jdbc
来源:互联网 发布:风油精提神 知乎 编辑:程序博客网 时间:2024/06/01 22:09
public static void init(){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = "jdbc:mysql://10.0.31.207:3309/gv_local?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true";
String userName ="root";
String pwd ="root123";
Connection con = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(url,userName,pwd);
statement = con.prepareStatement("select * from gv_alarm_view where id in(?)");
statement.setObject(1,new String[]{"7803","7805"});
rs = statement.executeQuery();
if (null != rs) {
int i=0;
while(rs.next()) {
i++;
System.out.println(""+rs.getLong("id"));
}
System.out.println("total:"+i);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close(con,statement,rs);
}
}
private static void close(Connection con,Statement sta,ResultSet rs){
if (null != rs) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (null != sta) {
try {
sta.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (null != con) {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = "jdbc:mysql://10.0.31.207:3309/gv_local?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true";
String userName ="root";
String pwd ="root123";
Connection con = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(url,userName,pwd);
statement = con.prepareStatement("select * from gv_alarm_view where id in(?)");
statement.setObject(1,new String[]{"7803","7805"});
rs = statement.executeQuery();
if (null != rs) {
int i=0;
while(rs.next()) {
i++;
System.out.println(""+rs.getLong("id"));
}
System.out.println("total:"+i);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close(con,statement,rs);
}
}
private static void close(Connection con,Statement sta,ResultSet rs){
if (null != rs) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (null != sta) {
try {
sta.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (null != con) {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
0 0
- jdbc
- JDBC
- jdbc
- JDBC
- jdbc
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- JDBC
- jdbc
- JDBC
- JDBC
- jdbc
- Windows Server AppFabric缓存服务的几点实用心得
- 《黑马程序员》 Executors线程池的使用练习
- 共享内存是最快的一种IPC方式
- C++与Java的语法区别
- Java线程池使用
- jdbc
- Python扩展和嵌入: Cython三分钟入门(笔记)
- Android 混淆机制
- Unity3d之MonoBehaviour的可重写函数整理
- 编程之美 2.18:数组分割 (涉及 动态规划)
- iOS App性能优化
- JAVA8新特性
- Struts2学习(第四篇)——struts2中action执行流程和源码分析
- html5新功能---拖放