package learn;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class Example01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String URL="jdbc:mysql://127.0.0.1:3306/test1";
String DRIVER="com.mysql.jdbc.Driver";
String USERNAME="root";
String PASSWD="123456";
String sql;
Connection connection =null;
try{
Class.forName(DRIVER);
connection=DriverManager.getConnection(URL,USERNAME,PASSWD);
Statement stmt = connection.createStatement();
sql = "select * from t1";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
}catch(SQLException e){
System.out.println("test1");
e.printStackTrace();
}catch(ClassNotFoundException e){
System.out.println("test2");
e.printStackTrace();
}finally{
try{
connection.close();
}catch(SQLException e){
System.out.println("test3");
e.printStackTrace();
}
}
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。