jdbc连接

<pre class="java" name="code">public class 连接
{
    public static void main(String[] args) throws ClassNotFoundException, SQLException
    {
        Class.forName("com.mysql.jdbc.Driver");
        String st ="jdbc:mysql://localhost:3306/scott";
        Connection ct = DriverManager.getConnection(st, "root", "l123456");
        Statement sm=ct.createStatement();
        String stSql = "select * from emp";
        ResultSet rs =sm.executeQuery(stSql);
        while(rs.next())
        {
            Integer nEmpno = rs.getInt("empno");
            String stName =rs.getString("ename");
            String stJob = rs.getString("job");
            System.out.println(nEmpno.toString()+" "+stName+" "+stJob);
        }
        rs.close();
        sm.close();
        ct.close();
    }
}

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class 插入
{
    public static void InsertDept(int deptno, String DeptName, String Loc) throws ClassNotFoundException, SQLException
    {

        Class.forName("oracle.jdbc.driver.OracleDriver");
        String st = "jdbc:oracle:thin:@localhost:1521:orcl";
        Connection ct = DriverManager.getConnection(st, "scott", "l123456");
        Statement sm = ct.createStatement();
        String stSQL = "insert into dept values("+deptno+",'"+DeptName+"','"+Loc+ "')";
        sm.executeUpdate(stSQL);
        sm.close();
        ct.close();
    }
    public static void main(String[] args) throws SQLException, ClassNotFoundException
    {
        InsertDept(60,"ZhuanYan","JinZhou");
    }
}

package com.company;

import java.util.Scanner;

/**
 * Created by ttc on 16-10-27.
 */
public class 练习
{
    public static void main(String[] args)
    {
        System.out.println("please input a string:");
        Scanner sc = new Scanner(System.in);
        String str=sc.nextLine();
        int [] word =new int[26];
//        for(int j = 0;j<26;j++)
//        {
//            System.out.print(word[j]);
//        }
//            System.out.println("");
        for(int i=0;i<str.length();i++)
        {
            char c = str.charAt(i);
            if(Character.isLetter(c))
            {
                int num = word[c - 'a'];
                num++;
                word[c - 'a'] = num;
            }
        }
        for(int j = 0;j<26;j++)
        {
            if(word[j]>0)
                System.out.println((char)('a'+j)+"出现了"+word[j]+"次");
        }
    }
}
<pre class="java" name="code">public class 连接
{
    public static void main(String[] args) throws ClassNotFoundException, SQLException
    {
        Class.forName("com.mysql.jdbc.Driver");
        String st ="jdbc:mysql://localhost:3306/scott";
        Connection ct = DriverManager.getConnection(st, "root", "l123456");
        Statement sm=ct.createStatement();
        String stSql = "select * from emp";
        ResultSet rs =sm.executeQuery(stSql);
        while(rs.next())
        {
            Integer nEmpno = rs.getInt("empno");
            String stName =rs.getString("ename");
            String stJob = rs.getString("job");
            System.out.println(nEmpno.toString()+" "+stName+" "+stJob);
        }
        rs.close();
        sm.close();
        ct.close();
    }
}

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class 插入
{
    public static void InsertDept(int deptno, String DeptName, String Loc) throws ClassNotFoundException, SQLException
    {

        Class.forName("oracle.jdbc.driver.OracleDriver");
        String st = "jdbc:oracle:thin:@localhost:1521:orcl";
        Connection ct = DriverManager.getConnection(st, "scott", "l123456");
        Statement sm = ct.createStatement();
        String stSQL = "insert into dept values("+deptno+",'"+DeptName+"','"+Loc+ "')";
        sm.executeUpdate(stSQL);
        sm.close();
        ct.close();
    }
    public static void main(String[] args) throws SQLException, ClassNotFoundException
    {
        InsertDept(60,"ZhuanYan","JinZhou");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值