0
0

More than 3 years have passed since last update.

db の接続のメモ

Posted at

DB接続メモ(大雑把に書きました)


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


Connection con;
preparedStatment pstmt;
ResultSet ts;

//1.DBと接続

con = DriverManager.getConnection(
            "jdbc:mysql://(DBのアドレス)",
            "(sqlid)",
            "(sqlpassword)"
        );

//2.dbとやり取りする
pstmt = don.prepareStatementsql文;

//3.selectb分の実行と結果を代入
rs.pstmt.executeQuery();

//4.結果を表示
while(rs.next()){

}catcg(SQLException e){
e.printStackTrace();
}fainally{
 DBのclose処理
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0