'mysql+php'에 해당되는 글 1건

  1. 2010/10/13 boyo 각종 웹언어 MYSQL 연결 방법

ASP+MYSQL


ODBC 사용(X)
Set dbCon =Server.CreateObject("Adodb.Connection")
dbCon.open("Driver={SQL Server};Server=서버이름 또는 IP;Database=데이타베이스명;uid=아이디;pwd=패스워드")


ODBC 사용(O)
Set dbCon = Server.CreateObject("ADODB.Connection")
strConnect = "DSN=testODBC;uid=testUser;pwd=1234;"
dbCon.Open strConnect
SQL = "Select * from testTable"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open SQL, dbCon




PHP+MYSQL


$connect = mysql_connect("서버주소", "계정명","비밀번호");
$mysql_select_db("디비명", $connect);
$sql="create database mydb";
$result = mysql_query($sql, $connect);




JSP+MYSQL
<%@page contentType="text/html;charset=EUC-KR" import="java.sql.*,java.util.*" %>
<%
 
  Connection conn=null;
  Statement stmt = null;
  ResultSet rs = null;
  PreparedStatement pstmt = null;
String connURL = "jdbc:mysql://localhost:3306/test";


  try{
 
  //dirver loading
   Class.forName("com.mysql.jdbc.Driver");
   out.print("forNameload");


   //datebase conn
   conn = DriverManager.getConnection(connURL,"root","pw");
   out.print("getConn");


  }catch(ClassNotFoundException ex){
  System.out.println("classnotfound"+ ex.getMessage());
  }catch(Exception e){
  System.out.println("Exception"+e.getMessage());
  }finally{
   try{
    if(stmt !=null)stmt.close();
     if(pstmt !=null)pstmt.close();
    if(conn !=null)conn.close();
   }catch(SQLException sqle){
     System.out.println("SQLException"+sqle.getMessage());
   }
  }
 
 %>




JAVA+MYSQL


import java.lang.*;
import java.sql.*;
public class DriverTest{
 public static void main(String args[]){
  Connection con;
  try{
   Class.forName("org.gjt.mm.mysql.Driver").newInstance();
// Class.forName("com.mysql.jdbc.Driver").newInstance();
   
   con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","pw");
System.out.println("Success!");
  }
  catch(SQLException ex){System.out.println("SQLException:"+ex);}
  catch(Exception ex){System.out.println("Exception:"+ex);}
 }
}
2010/10/13 14:27 2010/10/13 14:27