Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package jdbc;
- import java.io.*;
- import java.sql.*;
- /**
- *
- * @author MohanDhar
- */
- public class JDBC {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Connection conn=null;
- try{
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- String url = "jdbc:mysql://172.16.10.117/cs391";
- String dbuser = "cs391";
- String dbpass = "abc123";
- conn = DriverManager.getConnection(url,dbuser,dbpass);
- Statement s = conn.createStatement();
- s.execute("INSERT INTO TEST(Motto,NNum) VALUES('Rafi Rizwan','12265380');");//throws an exception if it fails
- }
- catch(Exception e){
- System.out.println("Connection error: "+e.toString());
- }
- finally{
- try{
- conn.close();
- System.out.println("Connection Closed!");
- }
- catch(Exception e){}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement