티스토리 뷰
반응형
mysql-connector-java 설치
[root@localhost]# wget http://mysql.new21.com/Downloads/Connector-J/mysql-connector-java-3.0.17-ga.tar.gz
[root@localhost]# tar xvfz mysql-connector-java-3.0.17-ga.tar.gz
[root@localhost]# cd mysql-connector-java-3.0.17-ga
[root@localhost]# cp mysql-connector-java-3.0.17-ga-bin.jar /usr/local/j2sdk/jre/lib/ext/
[root@localhost]# vi /etc/profile
JAVA_HOME=/usr/local/j2sdk
CATALINA_HOME=/usr/local/tomcat
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
export JAVA_HOME CATALINA_HOME
위의 부분을 다음과 같이 수정한다.
JAVA_HOME=/usr/local/j2sdk
CATALINA_HOME=/usr/local/tomcat
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$CATALINA_HOME/common/lib/servlet.jar:$JAVA_HOME/jre/lib/ext/mysql-connector-java-3.0.17-ga-bin.jar:/usr/local/mysql/bin
export JAVA_HOME CATALINA_HOME
저장 하고 나온다.
[root@localhost]# source /etc/profile
[root@localhost]# set | grep PATH
[root@localhost]# javap org.gjt.mm.mysql.Driver
하고 아래메시지가 나오면 정상이다.
Compiled from "Driver.java"
public class org.gjt.mm.mysql.Driver extends com.mysql.jdbc.Driver{
public org.gjt.mm.mysql.Driver();
throws java/sql/SQLException
}
[root@localhost]# cd /usr/local/tomcat/common/lib
[root@localhost]# ln -s /usr/local/j2sdk/jre/lib/ext/mysql-connector-java-3.0.17-ga-bin.jar /usr/local/tomcat/common/lib/mysql-connector-java-3.0.17-ga-bin.jar
자바 소스 테스트
[root@localhost]# cd /usr/local/src
[root@localhost]# vi jdbc.java
//--여기서부터-------------------------------------------------
import java.sql.*;
class jdbc
{
public static void main(String argv[])
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
System.out.println("jdbc 드라이버 로딩 성공");
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
try
{
String url = "jdbc:mysql://자신의 아이피:3306/mysql";
Connection con = DriverManager.getConnection(url,"root","");
System.out.println("mysql 접속 성공");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select user from user where user='root'");
System.out.println("Got result:");
while(rs.next())
{
String no= rs.getString(1);
String tblname = rs.getString(1);
System.out.println(" no = " + no);
System.out.println(" tblname= "+ tblname);
}
stmt.close();
con.close();
}
catch(java.lang.Exception ex)
{
ex.printStackTrace();
}
}
}
//--여기까지-------------------------------------------------
이제 부터 jsp에서 mysql연결 테스트 입니다.
[root@localhost]# cd /home/www
[root@localhost]# vi test.jsp
//--여기서부터-------------------------------------------------
<%@ page import="java.sql.*" contentType="text/html;charset=euc-kr"%>
<%
String DB_URL = "jdbc:mysql://자신의 아이피:3306/mysql";
String DB_USER = "root";
String DB_PASSWORD= "root비밀번호입력";
Connection conn;
Statement stmt;
try
{
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USER,DB_PASSWORD);
stmt = conn.createStatement();
conn.close();
out.println("MySQL 연결 성공");
}
catch(Exception e)
{
out.println(e);
}
%>
//--여기까지-------------------------------------------------
[root@localhost /]# /usr/local/apache2/bin/apachectl stop
[root@localhost /]# /usr/local/tomcat/bin/catalina.sh stop
[root@localhost /]# /usr/local/tomcat/bin/catalina.sh start
[root@localhost /]# /usr/local/apache2/bin/apachectl start
브라우저로 http://자신의 아이피/test.jsp
해서 "MySQL 연결 성공"이라는 메시지가 나오면 성공!!
[root@localhost]# wget http://mysql.new21.com/Downloads/Connector-J/mysql-connector-java-3.0.17-ga.tar.gz
[root@localhost]# tar xvfz mysql-connector-java-3.0.17-ga.tar.gz
[root@localhost]# cd mysql-connector-java-3.0.17-ga
[root@localhost]# cp mysql-connector-java-3.0.17-ga-bin.jar /usr/local/j2sdk/jre/lib/ext/
[root@localhost]# vi /etc/profile
JAVA_HOME=/usr/local/j2sdk
CATALINA_HOME=/usr/local/tomcat
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
export JAVA_HOME CATALINA_HOME
위의 부분을 다음과 같이 수정한다.
JAVA_HOME=/usr/local/j2sdk
CATALINA_HOME=/usr/local/tomcat
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$CATALINA_HOME/common/lib/servlet.jar:$JAVA_HOME/jre/lib/ext/mysql-connector-java-3.0.17-ga-bin.jar:/usr/local/mysql/bin
export JAVA_HOME CATALINA_HOME
저장 하고 나온다.
[root@localhost]# source /etc/profile
[root@localhost]# set | grep PATH
[root@localhost]# javap org.gjt.mm.mysql.Driver
하고 아래메시지가 나오면 정상이다.
Compiled from "Driver.java"
public class org.gjt.mm.mysql.Driver extends com.mysql.jdbc.Driver{
public org.gjt.mm.mysql.Driver();
throws java/sql/SQLException
}
[root@localhost]# cd /usr/local/tomcat/common/lib
[root@localhost]# ln -s /usr/local/j2sdk/jre/lib/ext/mysql-connector-java-3.0.17-ga-bin.jar /usr/local/tomcat/common/lib/mysql-connector-java-3.0.17-ga-bin.jar
자바 소스 테스트
[root@localhost]# cd /usr/local/src
[root@localhost]# vi jdbc.java
//--여기서부터-------------------------------------------------
import java.sql.*;
class jdbc
{
public static void main(String argv[])
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
System.out.println("jdbc 드라이버 로딩 성공");
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
try
{
String url = "jdbc:mysql://자신의 아이피:3306/mysql";
Connection con = DriverManager.getConnection(url,"root","");
System.out.println("mysql 접속 성공");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select user from user where user='root'");
System.out.println("Got result:");
while(rs.next())
{
String no= rs.getString(1);
String tblname = rs.getString(1);
System.out.println(" no = " + no);
System.out.println(" tblname= "+ tblname);
}
stmt.close();
con.close();
}
catch(java.lang.Exception ex)
{
ex.printStackTrace();
}
}
}
//--여기까지-------------------------------------------------
이제 부터 jsp에서 mysql연결 테스트 입니다.
[root@localhost]# cd /home/www
[root@localhost]# vi test.jsp
//--여기서부터-------------------------------------------------
<%@ page import="java.sql.*" contentType="text/html;charset=euc-kr"%>
<%
String DB_URL = "jdbc:mysql://자신의 아이피:3306/mysql";
String DB_USER = "root";
String DB_PASSWORD= "root비밀번호입력";
Connection conn;
Statement stmt;
try
{
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USER,DB_PASSWORD);
stmt = conn.createStatement();
conn.close();
out.println("MySQL 연결 성공");
}
catch(Exception e)
{
out.println(e);
}
%>
//--여기까지-------------------------------------------------
[root@localhost /]# /usr/local/apache2/bin/apachectl stop
[root@localhost /]# /usr/local/tomcat/bin/catalina.sh stop
[root@localhost /]# /usr/local/tomcat/bin/catalina.sh start
[root@localhost /]# /usr/local/apache2/bin/apachectl start
브라우저로 http://자신의 아이피/test.jsp
해서 "MySQL 연결 성공"이라는 메시지가 나오면 성공!!
반응형
'Linux' 카테고리의 다른 글
RedHat 9 (메일서버 (sendmail) 설치 및 운영) (0) | 2007.08.29 |
---|---|
mysql 사용자등록,기본사용법 (0) | 2007.08.29 |
* Tomcat 설치 (0) | 2007.08.29 |
* Apache 설치 (0) | 2007.08.29 |
Mysql 설치 (0) | 2007.08.29 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 백업
- 오라클
- apache
- mssql
- table
- eclipse
- user
- 데이터
- Toad
- delete
- 서버
- DB
- sql
- 리눅스
- Shell
- 자동차
- tomcat
- Linux
- server
- java
- 파일
- IP
- Oracle
- 테이블
- DATABASE
- Windows
- select
- 설정
- 윈도우
- MySQL
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
글 보관함