How to create a database with java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rotaryfreak
    New Member
    • Oct 2008
    • 74

    How to create a database with java

    Hi everyone,

    So ive basically searched the interwebs and tried some examples but i cant not seem to get this working. I would like to create a Java program in which i can save data into a database. The GUI part is not the problem, the problem is getting Java to communicate with MySQL. I have no idea how to establish a connection bewteen my Java program and MySQL.
    I have downloaded and installed wampserver 2.0 and i am pretty much lost after this point. Does anyone know of any good reading material that can help me out with this? maybe provide a small example?

    thanks a million!
  • ketan10
    New Member
    • Jul 2010
    • 2

    #2
    use jdbc odbc connection to connect to databases, may it be MySQL or MS Access or any other.
    Example: here emp table contains name & sal


    Code:
    import java.sql*;
    
    class JdbcDemo 
    {
    	public static void main(String[] args) 
    	{
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    		Connection con = DriverManager.getConnection("jdbc:odbc:ooo", "" , "");
    		Statement st = con.createStatement();
    		Resultset rs = st.executeQuery("select * from emp");
    		while(re.next())
    		{
    			System.out.println(rs.getString(1) + "\t" + rs.getInt(2));
    		}
    		con.close();
    
    
    	}
    }

    Comment

    Working...