javasolutions4all.blogspot.in includes all the data and metadata regarding interviews for freshers and experienced. In this blog you find out the basic Java programs generally asked in interviews. Core Java , Basic and advanced including JSP and Android based interview questions and answers.. Here we also include some Java solutions for programmers.
Tuesday, 16 October 2012
JDBC CONNECTION
JDBC connection with MysqlMost asked question by interviewers...
import java.sql.*;
public class InsertValues{
public static void main(String[] args)
{
System.out.println("Inserting values in Mysql database table!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "jdbctut";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{ Statement st = con.createStatement();
int val = st.executeUpdate("INSERT employee VALUES("+23+","+"'Pankaj'"+")"); System.out.println("1 row affected");
}
catch (SQLException s)
{ System.out.println("SQL statement is not executed!");
Great.!!!!!!!!!!!
ReplyDeleteNice Blog.
Keep It up.
Thanks man...
ReplyDelete