Skip to content

Instantly share code, notes, and snippets.

@duyet
Last active March 2, 2016 16:02
Show Gist options
  • Save duyet/9100a10e40a1c512cc31 to your computer and use it in GitHub Desktop.
Save duyet/9100a10e40a1c512cc31 to your computer and use it in GitHub Desktop.
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();
}
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