Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class Main{
- static final String DB_URL = "jdbc:mysql://ricky.heliohost.org/cackoa_database";
- static final String USER = "cackoa_user";
- static final String PASS = "cackoa_password";
- public static void main(String args[]){
- Connection polaczenie = null;
- java.sql.Statement stmt = null;
- try{
- // Połączenie z bazą danych
- System.out.println("Connecting to database...");
- polaczenie = DriverManager.getConnection(DB_URL,USER,PASS);
- // Stworzenie zapytania oraz jego wykonanie
- System.out.println("Creating statement...");
- stmt = polaczenie.createStatement();
- String sql2;
- sql2= "INSERT INTO student (ID,name,surname,student_group) VALUES (69,'Sebastian','Chojnacki',4)";
- stmt.execute(sql2);
- // Czyszczenie po sobie
- stmt.close();
- polaczenie.close();
- }
- catch(SQLException se){
- //Errory JDBC
- se.printStackTrace();
- }
- catch(Exception e){
- e.printStackTrace();
- }
- finally{
- //finally block - by pozamykać resources
- try{
- if(stmt!=null)
- stmt.close();
- }
- catch(SQLException se2){
- }// nothing we can do
- try{
- if(polaczenie!=null)
- polaczenie.close();
- }
- catch(SQLException se){
- se.printStackTrace();
- }//end finally try
- }//end try
- System.out.println("Koniec!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement