Last active
March 2, 2016 16:02
-
-
Save duyet/9100a10e40a1c512cc31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connection con = DBConnect.getConnecttion(); | |
String sql = "insert into category value(?,?,?)"; | |
PreparedStatement ps; | |
try { | |
ps = (PreparedStatement) con.prepareStatement(sql); | |
ps.setInt(1, 0); | |
ps.setString(2, "Abc"); | |
ps.setString(3, "Def"); | |
ps.executeUpdate(); | |
con.close(); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dao; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
public class DBConnect { | |
public static Connection getConnecttion() { | |
Connection cons = null; | |
try { | |
Class.forName("com.mysql.jdbc.Driver"); | |
cons = DriverManager.getConnection( | |
"jdbc:mysql://localhost:3306/image-gallery", "root", ""); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return cons; | |
} | |
public static void main(String[] args) { | |
System.out.println(getConnecttion()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment