📄 sqlselect.java
字号:
package com.test;
import java.sql.*;
public class sqlselect {
public Connection getCon() {
Connection con=null;
String url = "jdbc:mysql://www.busycode.com:3306/bigpapa";
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con = DriverManager.getConnection(url,"root","root");
}catch (ClassNotFoundException e) {
System.err.println("class not found:" + e.getMessage());}
catch (SQLException a) {
System.err.println("sql exception:" + a.getMessage());
}
catch (Exception d) {
System.err.println("sql exception:" + d.getMessage());
}
return con;
}
/**
* 执行一条简单的查询语句
* 返回取得的结果集
*/
public ResultSet executeQuery(String sql) {
Statement stmt=null;
ResultSet rs = null;
Connection con= this.getCon();
try {
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public boolean executeUpdate(String sql) {
Connection con=this.getCon();
Statement stmt=null;
boolean v = false;
try {
stmt = con.createStatement();
v = stmt.executeUpdate(sql) > 0 ? true : false;
}
catch (SQLException e) {
e.printStackTrace();
}
finally {
return v;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -