English Sentence Loading...
英语句子加载中...
一个JAVA与MYSQL连接的程序
作者:junyuqin 日期:2007-05-04
import java.sql.*;
import java.util.Date;
public class b
{
public static void main(String args[])
{
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("org.gjt.mm.mysql.Driver");
}//MYSQL的驱动
//try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}//MYSQL的驱动
catch(ClassNotFoundException e)
{
System.out.println(""+e);
}
try
{
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_name?user=root&password=123&Unicode=true&characterEncoding=gb2312");//将localhost改成IP地址就能与网络连接了
sql=con.createStatement();
rs=sql.executeQuery("Select * FROM student");
while (rs.next())
{
int nu=rs.getInt("no");
System.out.println("num:"+nu);
//System.out.println(rs.getInt(1));
}
con.close();
sql.close();
con.close();
}
catch (SQLException e1)
{
System.out.println("error:"+e1);
}
}
//库名为db_name,表名为student,第一个字段为no [int(4)].
}
import java.util.Date;
public class b
{
public static void main(String args[])
{
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("org.gjt.mm.mysql.Driver");
}//MYSQL的驱动
//try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}//MYSQL的驱动
catch(ClassNotFoundException e)
{
System.out.println(""+e);
}
try
{
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_name?user=root&password=123&Unicode=true&characterEncoding=gb2312");//将localhost改成IP地址就能与网络连接了
sql=con.createStatement();
rs=sql.executeQuery("Select * FROM student");
while (rs.next())
{
int nu=rs.getInt("no");
System.out.println("num:"+nu);
//System.out.println(rs.getInt(1));
}
con.close();
sql.close();
con.close();
}
catch (SQLException e1)
{
System.out.println("error:"+e1);
}
}
//库名为db_name,表名为student,第一个字段为no [int(4)].
}
评论: 0 | 引用: 0 | 查看次数: 4684
上一篇
下一篇


文章来自:
Tags: 