Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class JDBC{
- Connection con;
- String s1;
- String s2;
- String s3;
- String st="";
- public static void main(String[] args){
- JDBC j1 = new JDBC();
- }
- public String getR(){
- return st;
- }
- public JDBC(){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/activity","root","");
- Statement stmt = con.createStatement();
- ResultSet rst = stmt.executeQuery("SELECT * FROM sample");
- while (rst.next()){
- s1 = rst.getString(1);
- s2 = rst.getString(2);
- s3 = rst.getString(3);
- st += s1+s2+s3;
- System.out.println(s1 + " " + s2 + " " + s3);
- }
- }
- catch(Exception e){
- System.out.println(e);
- }
- /*finally{
- try{
- con.close();
- }
- catch (Exception e){
- }
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement